Documentation
¶
Overview ¶
Package apperrors defines shared error codes and exit-code mapping.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllExitCodes ¶
func AllExitCodes() []int
AllExitCodes returns every possible process exit code, including success.
Types ¶
type AppError ¶
type AppError struct {
Code ErrorCode `json:"code"`
Message string `json:"message"`
Suggestion string `json:"suggestion,omitempty"`
Cause string `json:"cause,omitempty"`
StructuredCause *ErrorCause `json:"-"`
HTTPStatus int `json:"-"`
Retryable bool `json:"-"`
Err error `json:"-"`
}
AppError carries structured error information for humans and JSON consumers.
func AsAppError ¶
AsAppError converts arbitrary errors to AppError.
func (*AppError) MarshalJSON ¶
MarshalJSON writes the stable public error shape. StructuredCause lets tools that need diagnostic subfields emit the same "cause" key without changing the string Cause field used by existing consumers.
func (*AppError) WithSuggestion ¶
WithSuggestion overrides the default recovery hint.
type Code ¶
type Code = ErrorCode
Code is kept as a short alias for consumers that name error codes tersely.
type ErrorCause ¶
ErrorCause is diagnostic-only. Machine consumers MUST use Code, not Cause.
type ErrorCode ¶
type ErrorCode string
ErrorCode is a stable machine-readable error code.
const ( CodeUsageError ErrorCode = "USAGE_ERROR" CodeNetworkError ErrorCode = "NETWORK_ERROR" CodeAuthFailed ErrorCode = "AUTH_FAILED" CodeResourceNotFound ErrorCode = "RESOURCE_NOT_FOUND" CodeResourceAlreadyExists ErrorCode = "RESOURCE_ALREADY_EXISTS" CodeLocalIOError ErrorCode = "LOCAL_IO_ERROR" CodeServerError ErrorCode = "SERVER_ERROR" CodeBackendUnreachable ErrorCode = "BACKEND_UNREACHABLE" CodeBackendError ErrorCode = "BACKEND_ERROR" CodeAuthorizationRequired ErrorCode = "AUTHORIZATION_REQUIRED" CodeValidationFailed ErrorCode = "VALIDATION_FAILED" CodeConflict ErrorCode = "CONFLICT" CodePartialFailure ErrorCode = "PARTIAL_FAILURE" CodeNoChangeRequired ErrorCode = "NO_CHANGE_REQUIRED" CodeUnsupportedProtocol ErrorCode = "UNSUPPORTED_PROTOCOL" CodeNotImplemented ErrorCode = "NOT_IMPLEMENTED" CodeCredentialStoreError ErrorCode = "CREDENTIAL_STORE_ERROR" //nolint:gosec // Error code constant, not a credential. CodeCredentialStoreMissing ErrorCode = "CREDENTIAL_STORE_MISSING" //nolint:gosec // Error code constant, not a credential. )