errors

package
v0.0.0-...-2bd5d0f Latest Latest
Warning

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

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

Documentation

Overview

Package errors provides structured application errors.

Index

Constants

This section is empty.

Variables

View Source
var (
	Unknown            = Kind{}
	InvalidArgument    = Kind{Code: "invalid_argument", Status: http.StatusBadRequest}
	InvalidInput       = Kind{Code: "invalid_input", Status: http.StatusUnprocessableEntity}
	Unauthenticated    = Kind{Code: "unauthenticated", Status: http.StatusUnauthorized}
	PermissionDenied   = Kind{Code: "permission_denied", Status: http.StatusForbidden}
	NotFound           = Kind{Code: "not_found", Status: http.StatusNotFound}
	MethodNotAllowed   = Kind{Code: "method_not_allowed", Status: http.StatusMethodNotAllowed}
	Conflict           = Kind{Code: "conflict", Status: http.StatusConflict}
	FailedPrecondition = Kind{Code: "failed_precondition", Status: http.StatusPreconditionFailed}
	PayloadTooLarge    = Kind{Code: "payload_too_large", Status: http.StatusRequestEntityTooLarge}
	ResourceExhausted  = Kind{Code: "resource_exhausted", Status: http.StatusTooManyRequests}
	Internal           = Kind{Code: "internal", Status: http.StatusInternalServerError}
	Unimplemented      = Kind{Code: "unimplemented", Status: http.StatusNotImplemented}
	Unavailable        = Kind{Code: "unavailable", Status: http.StatusServiceUnavailable}
	Canceled           = Kind{Code: "canceled", Status: http.StatusServiceUnavailable}
	DeadlineExceeded   = Kind{Code: "deadline_exceeded", Status: http.StatusServiceUnavailable}
	BadGateway         = Kind{Code: "bad_gateway", Status: http.StatusBadGateway}
)

Functions

func As

func As(err error, target any) bool

As finds the first error in err's chain that matches target.

func E

func E(args ...any) error

E builds an application error. Arguments are interpreted by type.

func Is

func Is(err, target error) bool

Is reports whether any error in err's chain matches target.

func Join

func Join(errs ...error) error

Join returns an error that wraps the given errors.

func LogDetailAttrs

func LogDetailAttrs(err error) []slog.Attr

LogDetailAttrs returns structured error details safe for logs.

func StatusCode

func StatusCode(err error) int

StatusCode returns the HTTP status code implied by err.

func Unwrap

func Unwrap(err error) error

Unwrap returns the result of calling err's Unwrap method, if any.

func UserMsg

func UserMsg(err error) string

UserMsg returns the safe user-facing message, if any.

Types

type Error

type Error struct {
	Op      string
	Kind    Kind
	Message string
	UserMsg string
	Err     error
}

Error carries structured context through the error chain.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Ops

func (e *Error) Ops() []string

Ops returns the logical operation chain.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the underlying error.

type Kind

type Kind struct {
	Code   string
	Status int
}

Kind classifies errors at application boundaries.

func KindFromStatus

func KindFromStatus(status int) Kind

func WhatKind

func WhatKind(err error) Kind

WhatKind returns the first structured kind in err's chain.

func (Kind) String

func (k Kind) String() string

type KindCarrier

type KindCarrier interface {
	ErrorKind() Kind
}

KindCarrier is implemented by custom error types that can provide an application kind.

type UserMessage

type UserMessage string

UserMessage is safe to expose to callers.

func User

func User(message string) UserMessage

User returns a user-facing message option.

Jump to

Keyboard shortcuts

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