apperr

package
v0.0.46 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 1 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 apperr provides a typed error that carries a stable, machine-readable code (and optional interpolation params) alongside a human-readable message.

The code lets the web frontend translate the error into the user's language via its i18n catalog, while the message remains a sensible fallback for any client that does not recognize the code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Code

func Code(err error) string

Code returns the stable code of err if it (or anything it wraps) is an *Error, or "" otherwise.

func Params

func Params(err error) map[string]any

Params returns the interpolation params of err if it (or anything it wraps) is an *Error, or nil otherwise.

Types

type Error

type Error struct {
	Code    string
	Message string
	// Params carries interpolation values for the localized message
	// (e.g. {"scope": "worker"}). Optional.
	Params map[string]any
	// contains filtered or unexported fields
}

Error is a business error with a stable code. The code is what the frontend maps to a localized string; Message is the (English) fallback.

func New

func New(code, message string) *Error

New builds a coded error with the given stable code and fallback message.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

func (*Error) WithParams

func (e *Error) WithParams(params map[string]any) *Error

WithParams attaches interpolation params and returns the error for chaining.

func (*Error) Wrapping

func (e *Error) Wrapping(err error) *Error

Wrapping sets an underlying error so errors.Is keeps matching it (used to preserve compatibility with domain sentinels like ErrValidation).

Jump to

Keyboard shortcuts

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