apperr

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 2 Imported by: ? 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 apperr classifies errors by what went wrong, not by how a transport reports it. Services return errors of a Kind; the HTTP layer (endpoints/httpx) turns the kind into a status code, so handlers never choose one.

Kinds are the constants KindNotFound, KindInvalid and so on. The constructors carry the plain name: NotFound, Invalid, Conflict, Busy, PreconditionRequired, Unsupported, Timeout, Forbidden and Internal.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Busy

func Busy(format string, args ...any) error

Busy is a resource that is in use by someone else.

func Conflict

func Conflict(format string, args ...any) error

Conflict is a request that clashes with the current state.

func Forbidden

func Forbidden(format string, args ...any) error

Forbidden is a request the caller may not make.

func Internal

func Internal(format string, args ...any) error

Internal is a failure of the hub itself.

func Invalid

func Invalid(format string, args ...any) error

Invalid is a request the caller has to correct.

func NotFound

func NotFound(format string, args ...any) error

NotFound is an entity that doesn't exist or isn't visible to the caller.

func PreconditionRequired

func PreconditionRequired(format string, args ...any) error

PreconditionRequired is a request that needs something first, such as a lease.

func Timeout

func Timeout(format string, args ...any) error

Timeout is an operation that took too long.

func Unsupported

func Unsupported(format string, args ...any) error

Unsupported is a capability the target doesn't have.

func Wrap

func Wrap(kind Kind, err error, msg string) error

Wrap gives err the kind and prefixes its message with msg ("msg: err"). The cause stays reachable through errors.Is and errors.As. Wrap of a nil error is nil.

Types

type Error

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

Error is an error with a Kind. It keeps the error it wraps for errors.Is and errors.As.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Kind

func (e *Error) Kind() Kind

Kind returns the kind of the error.

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Kind

type Kind int

Kind says what went wrong.

const (
	KindNone Kind = iota
	KindNotFound
	KindInvalid
	KindConflict
	KindBusy
	KindPreconditionRequired
	KindUnsupported
	KindTimeout
	KindForbidden
	KindInternal
)

KindNone is the kind of a nil error. Every non-nil error has a real kind; the ones that are not an *Error are KindInternal.

func KindOf

func KindOf(err error) Kind

KindOf returns the kind of the outermost *Error in the chain of err: KindNone for nil and KindInternal for an error that has none.

Jump to

Keyboard shortcuts

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