Documentation
¶
Overview ¶
Package errx provides structured error handling on top of github.com/joomcode/errorx. It owns two cross-cutting error properties — a machine-readable reason code and a list of human remediation hints — plus helpers to attach and extract them.
Convention ¶
Each subsystem package declares its own errorx namespace and a small set of typed errors in a local errors.go, e.g.:
var (
errNS = errorx.NewNamespace("uc")
errManifestInvalid = errNS.NewType("manifest_invalid")
errK8sAPI = errNS.NewType("k8s_api_failed", errorx.Temporary())
)
Errors are created from those types and decorated with a reason + hints:
return errx.WithHints(
errx.WithReason(errManifestInvalid.Wrap(err, "parse %s", path), "ManifestInvalid"),
"Regenerate the deployment package",
"Confirm manifests/consensus-node-components.yaml has schemaVersion: 1",
)
- The reason code is PascalCase so a log line, an error, and any /status
output line up on the same identifier.
- Hints are concrete next steps an operator can take; attach them only when
a meaningful remediation exists (config/disk/RBAC), not for internal bugs.
- Mark transient errors (worth a retry) with the errorx.Temporary() trait on
the type; terminal errors carry no such trait.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // PropertyReason carries the Reason code. It is printable, so it renders in // the error string for at-a-glance correlation. PropertyReason = errorx.RegisterPrintableProperty("reason") // PropertyResolution carries a []string of remediation hints — concrete next // steps an operator can take. It is surfaced by logging / diagnostic tooling // rather than embedded in the error message. PropertyResolution = errorx.RegisterProperty("resolution") )
Functions ¶
func Decorate ¶
Decorate attaches a reason code and optional hints in one call — the common case, equivalent to WithHints(WithReason(err, reason), hints...). Returns nil when err is nil.
func Format ¶
Format renders err for a human surface (a CLI failure, a fatal startup log): the full error message followed by a "Resolution:" block listing any attached remediation hints. When no hints are attached it returns err.Error() unchanged. Returns "" for a nil error.
func WithHints ¶
WithHints attaches remediation hints to err (err is wrapped if it is not already an errorx error). A call with no hints returns err unchanged.
func WithReason ¶
WithReason attaches a Reason code to err. err should already be an errorx error (from a Type.New/.Wrap); a plain error is wrapped so the reason is never silently dropped. Returns nil when err is nil.
Types ¶
type Reason ¶
type Reason string
Reason is a stable, machine-readable error/condition code. Callers define their own vocabulary as typed constants (e.g. `const ReasonX errx.Reason = "X"`) so reason codes are enumerable in one place and typo-safe at call sites. The convention is PascalCase so an error, its log line, and any status output share one identifier.