Documentation
¶
Overview ¶
Package errfmt is the central renderer for user-facing CLI errors.
Backend adapters classify wire errors into typed backend.DomainError values carrying a dotted ErrorCode. This package owns the mapping from code → human-readable title + hints, and writes them to the user via Render.
Why a dedicated package: presentation concerns (TTY colour, line shape, hint phrasing) drift over time, and code-level translations live close to the data they describe. Keeping both in one place stops the cmd layer from duplicating ad-hoc message strings.
Callers reach this package via cmdutil.ExplainError (legacy shim that most cmd/* packages still go through) or directly via Render in new code paths.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CatalogueHints ¶ added in v1.81.0
CatalogueHints returns the raw (un-expanded) hint templates for every error code in the catalogue. Consumed by the hint↔flag contract test to verify that every flag token in a hint is registered on the root cobra command.
func HintsFor ¶ added in v1.19.0
func HintsFor(de *backend.DomainError) []string
HintsFor returns the catalogue's hint strings for de.Code with template placeholders ({{.Host}}, {{.ID}}, {{.Resource}}, {{.Feature}}) expanded against the DomainError. Returns nil when de is nil, when the Code is empty, or when no catalogue entry exists for the code.
MCP and other structured-output surfaces use this to populate the "hints" field of their error envelope so clients see the same remediation steps as CLI users without bundling their own catalogue.
func Render ¶
Render writes a friendly error explanation to ios.ErrOut.
Resolution order:
- nil → no-op (safe to call from generic shims).
- DomainError whose Code is present in the catalogue → templated title/cause/hint output.
- DomainError whose Code is unset OR not in the catalogue, but whose Kind matches one of backend.ErrConflict / ErrUnsupportedOnHost / ErrPermission / ErrNotFound → Kind-based fallback line.
- anything else (including DomainErrors with no Code and no recognised Kind, or non-DomainError values) → raw error string.
Every server- or config-derived field (Message, Host, Resource, ID, Feature) is passed through sanitise before reaching ios.ErrOut to neutralise terminal escape injection (CWE-150 / CWE-117).
Types ¶
This section is empty.