errors

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
var (
	ErrNotFound      = errors.New("not found")
	ErrAlreadyExists = errors.New("already exists")
	ErrInvalidInput  = errors.New("invalid input")
	ErrUnauthorized  = errors.New("unauthorized")
	ErrForbidden     = errors.New("forbidden")
	ErrInternal      = errors.New("internal error")
	ErrConflict      = errors.New("conflict")
	ErrTimeout       = errors.New("timeout")
	ErrUnavailable   = errors.New("service unavailable")
)

Generic.

View Source
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.

View Source
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.

View Source
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.

View Source
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.

View Source
var (
	ErrConfigInvalid = errors.New("invalid configuration")
	ErrConfigMissing = errors.New("missing required configuration")
)

Configuration.

View Source
var As = errors.As

As is a convenience re-export.

View Source
var Is = errors.Is

Is is a convenience re-export so callers don't need to import stdlib errors.

View Source
var New = errors.New

New is a convenience re-export for creating simple sentinel errors.

Functions

func GetDetails

func GetDetails(err error) map[string]string

GetDetails extracts the detail map from any error in the chain. Returns an empty (non-nil) map if no *Error is found.

func Wrap

func Wrap(err error, msg string) error

Wrap wraps err with additional context message (fmt.Errorf %w style).

func Wrapf

func Wrapf(err error, format string, args ...any) error

Wrapf wraps err with a formatted context message.

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

func NewError(err error) *Error

NewError wraps a sentinel error, preserving any details already present if err is itself an *Error.

func NewErrorf

func NewErrorf(format string, args ...any) *Error

NewErrorf wraps a formatted error message as a new sentinel.

func (*Error) AddDetail

func (e *Error) AddDetail(key, value string) *Error

AddDetail attaches a key-value pair to the error and returns itself for fluent chaining: errors.NewError(ErrNotFound).AddDetail("id", id).

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface.

func (*Error) GetDetails

func (e *Error) GetDetails() map[string]string

GetDetails returns the detail map (never nil).

func (*Error) Is

func (e *Error) Is(target error) bool

Is delegates to the wrapped sentinel so errors.Is works transparently.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap exposes the wrapped error for errors.As / errors.Is traversal.

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"
	ErrCodeUnauthorized    ErrorCode = "UNAUTHORIZED"
	ErrCodeForbidden       ErrorCode = "FORBIDDEN"
	ErrCodeConflict        ErrorCode = "CONFLICT"
	ErrCodeValidationError ErrorCode = "VALIDATION_ERROR"
)

Jump to

Keyboard shortcuts

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