errors

package
v1.1.59 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrCodeHTTPClient       = "http_client_error"
	ErrCodeSystemError      = "system_error"
	ErrCodeInternalError    = "internal_error"
	ErrCodeNotFound         = "not_found"
	ErrCodeAlreadyExists    = "already_exists"
	ErrCodeVersionConflict  = "version_conflict"
	ErrCodeValidation       = "validation_error"
	ErrCodeInvalidOperation = "invalid_operation"
	ErrCodePermissionDenied = "permission_denied"
	ErrCodeDatabase         = "database_error"
)

Variables

View Source
var (
	ErrNotFound         = new(ErrCodeNotFound, "resource not found")
	ErrAlreadyExists    = new(ErrCodeAlreadyExists, "resource already exists")
	ErrVersionConflict  = new(ErrCodeVersionConflict, "version conflict")
	ErrValidation       = new(ErrCodeValidation, "validation error")
	ErrInvalidOperation = new(ErrCodeInvalidOperation, "invalid operation")
	ErrPermissionDenied = new(ErrCodePermissionDenied, "permission denied")
	ErrHTTPClient       = new(ErrCodeHTTPClient, "http client error")
	ErrDatabase         = new(ErrCodeDatabase, "database error")
	ErrSystem           = new(ErrCodeSystemError, "system error")
	ErrInternal         = new(ErrCodeInternalError, "internal error")
)

Common error types that can be used across the application TODO: move to errors.New from cockroachdb/errors

Functions

func As added in v1.0.0

func As(err error, target any) bool

func HTTPStatusFromErr

func HTTPStatusFromErr(err error) int

func IsAlreadyExists

func IsAlreadyExists(err error) bool

IsAlreadyExists checks if an error is an already exists error

func IsDatabase added in v1.0.0

func IsDatabase(err error) bool

func IsHTTPClient

func IsHTTPClient(err error) bool

IsHTTPClient checks if an error is an http client error

func IsInternal added in v1.0.17

func IsInternal(err error) bool

func IsInvalidOperation

func IsInvalidOperation(err error) bool

IsInvalidOperation checks if an error is an invalid operation error

func IsNotFound

func IsNotFound(err error) bool

IsNotFound checks if an error is a not found error

func IsPermissionDenied

func IsPermissionDenied(err error) bool

IsPermissionDenied checks if an error is a permission denied error

func IsSystem added in v1.0.0

func IsSystem(err error) bool

func IsValidation

func IsValidation(err error) bool

IsValidation checks if an error is a validation error

func IsVersionConflict

func IsVersionConflict(err error) bool

IsVersionConflict checks if an error is a version conflict error

Types

type ErrorBuilder

type ErrorBuilder struct {
	// contains filtered or unexported fields
}

ErrorBuilder provides a fluent interface for building errors but does not implement the error interface. This is intentional. Mark must be the last call in the chain when using the builder.

func NewError

func NewError(msg string) *ErrorBuilder

NewError starts a new error builder chain

func NewErrorf added in v1.0.13

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

func WithError

func WithError(err error) *ErrorBuilder

WithError starts a builder chain with an existing error

func (*ErrorBuilder) Error

func (b *ErrorBuilder) Error() error

Err returns the error string

func (*ErrorBuilder) Mark

func (b *ErrorBuilder) Mark(reference error) error

Mark marks the error with a sentinel error should be the last call in the chain

func (*ErrorBuilder) WithHint

func (b *ErrorBuilder) WithHint(hint string) *ErrorBuilder

WithHint adds context to the error this is for the frontend error messages

func (*ErrorBuilder) WithHintf

func (b *ErrorBuilder) WithHintf(format string, args ...any) *ErrorBuilder

WithHintf is a helper for WithHint that allows for formatting

func (*ErrorBuilder) WithMessage

func (b *ErrorBuilder) WithMessage(msg string) *ErrorBuilder

WithMessage adds context to the error this is for the internal error messages

func (*ErrorBuilder) WithMessagef added in v1.0.0

func (b *ErrorBuilder) WithMessagef(format string, args ...any) *ErrorBuilder

func (*ErrorBuilder) WithReportableDetails

func (b *ErrorBuilder) WithReportableDetails(details map[string]any) *ErrorBuilder

WithReportableDetails adds structured details

type ErrorDetail

type ErrorDetail struct {
	Display       string         `json:"message"`
	InternalError string         `json:"internal_error,omitempty"`
	Details       map[string]any `json:"details,omitempty" swaggerignore:"true"`
}

ErrorDetail contains error information

type ErrorResponse

type ErrorResponse struct {
	Success bool        `json:"success"`
	Error   ErrorDetail `json:"error"`
}

ErrorResponse represents the standard error response structure

type InternalError

type InternalError struct {
	Code    string // Machine-readable error code
	Message string // Human-readable error message
	Op      string // Logical operation name
	Err     error  // Underlying error
}

InternalError represents a domain error

func (*InternalError) DisplayError

func (e *InternalError) DisplayError() string

func (*InternalError) Error

func (e *InternalError) Error() string

func (*InternalError) Is

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

Is implements error matching for wrapped errors

func (*InternalError) Unwrap

func (e *InternalError) Unwrap() error

Jump to

Keyboard shortcuts

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