xerrors

package
v0.9.43 Latest Latest
Warning

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

Go to latest
Published: May 23, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As[T error](rawErr error) (T, bool)

func As0

func As0[T error](rawErr error) bool

func Is

func Is(err, target error) bool

func IsNot

func IsNot(err, target error) bool

func NoErr

func NoErr(err error)

func NoErr2

func NoErr2[T any](val T, err error) T

Types

type CodedError added in v0.9.28

type CodedError struct {
	Code       ErrorCode
	Message    string
	Extensions map[string]any
	Cause      error
}

CodedError is an error with a machine-readable code.

func AlreadyExistsError added in v0.9.28

func AlreadyExistsError(resource string) *CodedError

AlreadyExistsError creates a generic already exists error.

func DuplicateNameError added in v0.9.28

func DuplicateNameError(resource, name string) *CodedError

DuplicateNameError creates an error for duplicate name conflicts.

func ForbiddenError added in v0.9.28

func ForbiddenError(message string) *CodedError

ForbiddenError creates a forbidden error.

func IsCodedError added in v0.9.28

func IsCodedError(err error) (*CodedError, bool)

IsCodedError checks if an error is a CodedError.

func NewCodedError added in v0.9.28

func NewCodedError(code ErrorCode, message string) *CodedError

NewCodedError creates a new coded error.

func NewCodedErrorWithExtensions added in v0.9.28

func NewCodedErrorWithExtensions(code ErrorCode, message string, extensions map[string]any) *CodedError

NewCodedErrorWithExtensions creates a coded error with extensions.

func NotFoundError added in v0.9.28

func NotFoundError(resource string) *CodedError

NotFoundError creates a not found error.

func UnauthorizedError added in v0.9.28

func UnauthorizedError(message string) *CodedError

UnauthorizedError creates an unauthenticated error.

func ValidationError added in v0.9.28

func ValidationError(message string) *CodedError

ValidationError creates a validation error.

func (*CodedError) Error added in v0.9.28

func (e *CodedError) Error() string

Error implements the error interface.

func (*CodedError) Unwrap added in v0.9.28

func (e *CodedError) Unwrap() error

Unwrap returns the underlying error.

func (*CodedError) WithCause added in v0.9.28

func (e *CodedError) WithCause(err error) *CodedError

WithCause adds a cause error.

func (*CodedError) WithExtension added in v0.9.28

func (e *CodedError) WithExtension(key string, value any) *CodedError

WithExtension adds a single extension.

type ErrorCode added in v0.9.28

type ErrorCode string

ErrorCode represents application error codes These codes can be mapped to GraphQL extensions.code.

const (
	// ErrCodeInvalidInput indicates a generic invalid input.
	ErrCodeInvalidInput ErrorCode = "INVALID_INPUT"
	// ErrCodeValidationFailed indicates validation failure.
	ErrCodeValidationFailed ErrorCode = "VALIDATION_FAILED"

	// ErrCodeDuplicateName indicates duplicate name conflict.
	ErrCodeDuplicateName ErrorCode = "DUPLICATE_NAME"
	// ErrCodeAlreadyExists indicates resource already exists.
	ErrCodeAlreadyExists ErrorCode = "ALREADY_EXISTS"

	// ErrCodeNotFound indicates requested resource was not found.
	ErrCodeNotFound ErrorCode = "NOT_FOUND"

	// ErrCodeUnauthenticated indicates authentication is required.
	ErrCodeUnauthenticated ErrorCode = "UNAUTHENTICATED"
	// ErrCodeForbidden indicates insufficient permissions.
	ErrCodeForbidden ErrorCode = "FORBIDDEN"

	// ErrCodeInternalServerError indicates an unexpected server error.
	ErrCodeInternalServerError ErrorCode = "INTERNAL_SERVER_ERROR"
)

Jump to

Keyboard shortcuts

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