Documentation
¶
Overview ¶
Package errors provides structured error types for OpenArtifact.
Inspired by the zot project (https://github.com/project-zot/zot): errors wrap a sentinel error and carry a key-value detail map that survives the error chain, enabling rich context at log/response time.
Usage:
return errors.NewError(errors.ErrNotFound).AddDetail("repo", name)
if errors.Is(err, errors.ErrNotFound) { ... }
if details := errors.GetDetails(err); details["repo"] != "" { ... }
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("not found") ErrAlreadyExists = errors.New("already exists") ErrInvalidInput = errors.New("invalid input") ErrForbidden = errors.New("forbidden") ErrInternal = errors.New("internal error") ErrConflict = errors.New("conflict") ErrTimeout = errors.New("timeout") )
Generic.
var ( ErrBlobNotFound = errors.New("blob not found") ErrBlobExists = errors.New("blob already exists") ErrStorageBackend = errors.New("storage backend error") ErrChecksumMismatch = errors.New("checksum mismatch") )
Storage / blob.
var ( ErrRepoNotFound = errors.New("repository not found") ErrRepoExists = errors.New("repository already exists") ErrPackageNotFound = errors.New("package not found") ErrFormatInvalid = errors.New("invalid package format") ErrFormatNotFound = errors.New("format handler not found") )
Repository / package.
var ( ErrAuthFailed = errors.New("authentication failed") ErrTokenInvalid = errors.New("invalid token") ErrTokenExpired = errors.New("token expired") ErrSessionNotFound = errors.New("session not found") ErrUserNotFound = errors.New("user not found") ErrUserDisabled = errors.New("user account disabled") ErrPermissionDenied = errors.New("permission denied") ErrSSOProviderNotFound = errors.New("SSO provider not found") )
Auth / SSO.
var ( ErrDBConnection = errors.New("database connection error") ErrDBQuery = errors.New("database query error") ErrDBTransaction = errors.New("database transaction error") ErrDBMigration = errors.New("database migration error") )
Database.
var ( ErrConfigInvalid = errors.New("invalid configuration") ErrConfigMissing = errors.New("missing required configuration") )
Configuration.
var As = errors.As
As is a convenience re-export.
var Is = errors.Is
Is is a convenience re-export so callers don't need to import stdlib errors.
var New = errors.New
New is a convenience re-export for creating simple sentinel errors.
Functions ¶
func GetDetails ¶
GetDetails extracts the detail map from any error in the chain. Returns an empty (non-nil) map if no *Error is found.
Types ¶
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error wraps a sentinel error and carries structured key-value details. Details survive wrapping via errors.As, enabling rich context at any point in the call stack without losing the original sentinel identity.
func NewError ¶
NewError wraps a sentinel error, preserving any details already present if err is itself an *Error.
func (*Error) AddDetail ¶
AddDetail attaches a key-value pair to the error and returns itself for fluent chaining: errors.NewError(ErrNotFound).AddDetail("id", id).
func (*Error) GetDetails ¶
GetDetails returns the detail map (never nil).
type ErrorCode ¶
type ErrorCode = string
ErrorCode is a string error code.
const ( ErrCodeInvalidInput ErrorCode = "INVALID_INPUT" ErrCodeNotFound ErrorCode = "NOT_FOUND" ErrCodeAlreadyExists ErrorCode = "ALREADY_EXISTS" ErrCodeFormatNotFound ErrorCode = "FORMAT_NOT_FOUND" ErrCodeInternalError ErrorCode = "INTERNAL_ERROR" ErrCodeForbidden ErrorCode = "FORBIDDEN" ErrCodeConflict ErrorCode = "CONFLICT" ErrCodeValidationError ErrorCode = "VALIDATION_ERROR" )