Expand description
Substrate primitive over Result<T, E> for any E: [std::fmt:: Display] — the ONE substrate owner of the generic .map_err(|e| anyhow::anyhow!("<ctx>: {e}")) display-prefix wrap-shape for
consumers whose source error is a bare Display type NOT already
covered by a per-error-type flatten-wrap peer.
Peer of the type-specific flatten-wrap trait trio already in this crate on the same display-prefix wrap axis, partitioning the space by SPECIFICITY:
crate::kube_error::KubeResultExt::kube_ctx— the specialized peer forResult<T, kube::Error>, kept becausekube::Error’sDisplaycomposes the request URI + status line in a shape every reconciler-side callsite already greps on.crate::hostname::HostnameResultExt::hostname_ctx— the specialized peer forResult<T,crate::hostname::HostnameError>, kept because thethiserror-derivedDisplayoutput matches the pre-lift hand-authored render_routing log stream verbatim.crate::anyhow_flatten::FlattenCtxExt::flatten_ctx— the specialized peer foranyhow::Result<T>, kept because it collides withanyhow::Context::context’s naming so the distinct-method-name discipline (flatten-prefix vs. chain-wrap semantics) is load-bearing at every phase-machine callsite.ErrCtxExt::err_ctx(this trait) — the generic fallback for anyE: DisplayNOT covered by the three specialized peers, so a new consumer whose source error is a fresh [crate::tagged_union::declare_tagged_union_error]-derived variant (e.g.crate::export::ArtifactError,crate::intent::IntentError,crate::lifetime::LifetimeError) reaches the display-prefix wrap-shape mechanically at ONE substrate owner instead of opening a fourth per-error-type peer trait for every freshthiserror-derived enum.
Pre-lift the shape was hand-authored at TWO
tatara-export-worker/src/main.rs sites past the ★★ PRIME-DIRECTIVE
≥ 2 duplication threshold, both restating the SAME closure —
capture an crate::export::ArtifactError returned by the
substrate primitive crate::export::ArtifactSource::variant,
prepend the identical static context slug "source", delegate
the tail to std::fmt::Display via the {e} slot — differing
in NOTHING but their line numbers. Post-lift both callsites read
spec.source.variant().err_ctx("source")? and the wrap-shape
lives at ONE substrate owner here.
§Naming — err_ctx, not context
Same discipline as the three specialized peers: the method name
err_ctx is deliberately DISTINCT from anyhow::Context::context
so a caller with anyhow::Context in scope can never resolve to
the wrong method (which chain-wraps rather than display-prefix-
flattens, and would silently drop the underlying error detail from
every downstream tracing::error!(error = %e, ...) log line whose
formatter interpolates {e} rather than the chain-walking {e:#}).
§Two flavors: err_ctx + err_ctx_with
ErrCtxExt::err_ctxtakes a&'static strcontext — the most common shape ("source"at the two export-worker callsites). Static binding keeps the compile-time contract that the context slug is a bare literal, no allocation, no dynamic content leaking into an error stream downstream operators grep on.ErrCtxExt::err_ctx_withtakes an ownedStringcontext — the escape hatch for future consumers that compose the slug viaformat!(e.g. a dynamic per-variant-name slug the waycrate::anyhow_flatten::FlattenCtxExt::flatten_ctx_withalready services forphase_machine::evaluate_conditions).
§#[must_use]
Every consumer threads the ? short-circuit onto its handler’s
anyhow::Result<_> return — dropping the wrap swallows the
underlying failure entirely, which is never the intended
semantic.
Theory anchor: THEORY.md §VI.1 (generation over composition — the
generic display-prefix wrap-shape recurred at two byte-identical
hand-authored sites in tatara-export-worker/src/main.rs past
the ★★ PRIME-DIRECTIVE ≥ 2 duplication trigger, and is lifted to
ONE substrate owner here). THEORY.md §II.1 invariant 5
(composition preserves proofs — a regression that drifts the
display-prefix separator or the byte-shape surfaces here at the
substrate pin rather than as silent operator-facing skew across
every downstream err_ctx consumer).
Traits§
- ErrCtx
Ext - Substrate extension trait over
Result<T, E>for anyE:std::fmt::Display— the ONE substrate owner of the generic.map_err(|e| anyhow::anyhow!("<ctx>: {e}"))display-prefix wrap-shape for consumers whose source error is a bareDisplaytype NOT already covered by a per-error-type flatten-wrap peer. See the module docs for the specialized-peer partition + the naming rationale (whyerr_ctxand notcontext).