errors

package
v0.6.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package errors provides standardized error types and exit codes for gpd.

Index

Constants

View Source
const (
	ExitSuccess          = 0 // Command succeeded
	ExitGeneralError     = 1 // Other API errors
	ExitAuthFailure      = 2 // Authentication failures
	ExitPermissionDenied = 3 // Permission denied
	ExitValidationError  = 4 // Input validation errors
	ExitRateLimited      = 5 // Rate limit exceeded (HTTP 429 or quota)
	ExitNetworkError     = 6 // Network errors (DNS, TLS, timeouts)
	ExitNotFound         = 7 // Resource not found
	ExitConflict         = 8 // Conflicts (edit exists, file lock contention)
)

Exit codes for gpd CLI following the requirements specification.

Variables

View Source
var (
	ErrAuthNotConfigured = NewAPIError(CodeAuthFailure, "authentication not configured").
							WithHint("Provide --key, set GPD_SERVICE_ACCOUNT_KEY, or set GOOGLE_APPLICATION_CREDENTIALS")

	ErrServiceAccountInvalid = NewAPIError(CodeAuthFailure, "invalid service account key").
								WithHint("Ensure the service account key file is valid JSON and contains required fields")

	ErrPermissionDenied = NewAPIError(CodePermissionDenied, "permission denied").
						WithHint("Ensure the service account has required permissions in Google Play Console")

	ErrPackageRequired = NewAPIError(CodeValidationError, "package name is required").
						WithHint("Provide --package flag or set default package in config")

	ErrTrackInvalid = NewAPIError(CodeValidationError, "invalid track name").
					WithHint("Valid tracks are: internal, alpha, beta, production")

	ErrEditConflict = NewAPIError(CodeConflict, "edit transaction conflict").
					WithHint("Another process may be using this edit. Wait and retry, or use a different --edit-id")

	ErrFileLockTimeout = NewAPIError(CodeConflict, "file lock acquisition timeout").
						WithHint("Another gpd process may be running. Wait for it to complete or check for stale locks")
)

Common errors with hints.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Code              ErrorCode   `json:"code"`
	Message           string      `json:"message"`
	Hint              string      `json:"hint,omitempty"`
	Details           interface{} `json:"details,omitempty"`
	HTTPStatus        int         `json:"httpStatus,omitempty"`
	RetryAfterSeconds int         `json:"retryAfterSeconds,omitempty"`
	Service           string      `json:"service,omitempty"`
	Operation         string      `json:"operation,omitempty"`
}

APIError represents a structured error response.

func ClassifyAuthError

func ClassifyAuthError(err error) *APIError

func NewAPIError

func NewAPIError(code ErrorCode, message string) *APIError

NewAPIError creates a new APIError with the given parameters.

func (*APIError) Error

func (e *APIError) Error() string

Error implements the error interface.

func (*APIError) ExitCode

func (e *APIError) ExitCode() int

ExitCode returns the appropriate exit code for this error.

func (*APIError) WithDetails

func (e *APIError) WithDetails(details interface{}) *APIError

WithDetails adds details to the error.

func (*APIError) WithHTTPStatus

func (e *APIError) WithHTTPStatus(status int) *APIError

WithHTTPStatus adds HTTP status to the error.

func (*APIError) WithHint

func (e *APIError) WithHint(hint string) *APIError

WithHint adds a hint to the error.

func (*APIError) WithOperation

func (e *APIError) WithOperation(operation string) *APIError

WithOperation adds operation name to the error.

func (*APIError) WithRetryAfter

func (e *APIError) WithRetryAfter(seconds int) *APIError

WithRetryAfter adds retry-after seconds to the error.

func (*APIError) WithService

func (e *APIError) WithService(service string) *APIError

WithService adds service name to the error.

type ErrorCode

type ErrorCode string

ErrorCode represents a string error code for structured error responses.

const (
	CodeSuccess          ErrorCode = "SUCCESS"
	CodeGeneralError     ErrorCode = "GENERAL_ERROR"
	CodeAuthFailure      ErrorCode = "AUTH_FAILURE"
	CodePermissionDenied ErrorCode = "PERMISSION_DENIED"
	CodeValidationError  ErrorCode = "VALIDATION_ERROR"
	CodeRateLimited      ErrorCode = "RATE_LIMITED"
	CodeNetworkError     ErrorCode = "NETWORK_ERROR"
	CodeNotFound         ErrorCode = "NOT_FOUND"
	CodeConflict         ErrorCode = "CONFLICT"
)

func FromHTTPStatus

func FromHTTPStatus(status int) ErrorCode

FromHTTPStatus creates an appropriate error code from HTTP status.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL