Skip to main content

error_ctx

Function error_ctx 

Source
pub fn error_ctx(verb: &str, ns: &str, name: &str) -> String
Expand description

Compose the diagnostic-body head every wire-verb failure against a namespaced Process wraps around the underlying error via crate::kube_error::KubeResultExt::kube_ctx_with or the sibling anyhow::Context::with_context closure form.

Owns the fixed <verb> Process <ns>/<name> shape as ONE substrate site, routing the <ns>/<name> join through the workspace-wide crate::qualified_process_ref composer so a future normalization of the qualified-ref shape (case-fold, unicode collation, IDN) lands at ONE site and every Process-scoped diagnostic body picks it up mechanically.

Sibling to crate::configmap::error_ctx on the (per-Kind × substrate-owned error-slug) axis-family — that primitive owns the fixed "ConfigMap" resource-kind literal on the K8s-built-in ConfigMap axis; THIS primitive owns the fixed "Process" resource-kind literal on the tatara CRD axis. Both share the discipline of routing the failure-diagnostic head through ONE substrate composer per K8s-Kind rather than restating the shape as a bare format!(…) chain at every consumer. And both share the workspace-canonical TitleCase resource-kind spelling ("ConfigMap" / "Process") — matching the sibling crate::list::error_ctx’s TitleCase-plural convention ("Processes") so an operator grepping across the fleet on the canonical kube-canonical form hits every diagnostic surface.

Pre-lift the 3-slot format!("{verb} process {ns}/{name}: {e}") chain (with lowercase process, DRIFTING from the workspace- canonical TitleCase Process the sibling crate::list::error_ctx pins for the plural spelling) recurred at TWO hand-authored sites past the ★★ PRIME-DIRECTIVE ≥ 2 duplication threshold across two crates:

  • tatara-reconciler::boundary::evaluate_process_phase — verb "fetch", wrapping the Api<Process>::get_opt(&process_ref) fetch that the ConditionKind::ProcessPhase boundary evaluator dispatches for every dependency probe / postcondition Process phase read.
  • tatara-export-worker::main::read_artifact — verb "get", wrapping the Api<Process>::get(name) fetch on the ProcessSnapshotSource arm that serializes the owning Process’s spec + status into the export artifact stream.

Both sites walked the SAME shape — take a verb, the target Process’s namespace + name, and the underlying error’s display — and produced the SAME "<verb> process <ns>/<name>: <error>" diagnostic. Post-lift each callsite reads process_api::error_ctx(<verb>, ns, name) and pipes the returned context string through crate::kube_error::KubeResultExt::kube_ctx_with (the boundary consumer) or through anyhow::Context::with_context (the export-worker consumer, whose kube::Error bubbles through anyhow’s own Error + Send + Sync + 'static bound); both tails own the same ": {e}" suffix so the composed diagnostic is byte-identical to the pre-lift shape modulo the intentional TitleCase-kind drift-close.

§Wire-form drift close

The lift intentionally changes process (lowercase) to Process (TitleCase) at both consumers’ operator-facing diagnostics — closing a workspace-wide wire-form drift where the plural-list axis at crate::list::error_ctx pinned TitleCase ("Processes"), the ConfigMap-write axis at crate::configmap::error_ctx pinned TitleCase ("ConfigMap"), but the singular-fetch axis at these two consumer sites had drifted to lowercase ("process"). Post- lift every substrate-owned failure-diagnostic head across the fleet uses the kube-canonical TitleCase kind spelling so a fleet-wide grep 'Process default/api' on operator log streams matches EVERY Process-scoped failure body — the fetch corner alongside the list corner alongside the ConfigMap-write corner.

A future normalization step — a tracing-annotated span carrying the verb + qualified-ref for post-hoc audit, a per-verb structured- error kind so operators filter by fetch-verb rather than substring- match on the message body, a wire-time hedging of the verb spelling ("GET" vs "get" per a fleet convention), injection of a per- cluster prefix for a shared-controller deployment — lands at THIS ONE substrate primitive and every downstream Process-scoped failure diagnostic across the fleet picks up the upgrade mechanically. Future third + fourth consumers (a receipt-GC controller that fetches a Process by owner-ref for a reap decision, a cross-namespace routing walker that reads a Process to derive an Ingress alias) inherit the primitive at their own callsites with no per-site drift surface.

Theory anchor: THEORY.md §VI.1 (generation over composition — the 3-slot format!(…) chain recurred at 2 hand-authored sites past the ★★ PRIME-DIRECTIVE ≥ 2 duplication trigger and is lifted onto the ONE workspace-wide substrate owner here). THEORY.md §II.1 invariant 5 (composition preserves proofs — the pin block below binds the composer at fail-before-pass-after granularity, so a regression that reordered the head slots, drifted the fixed "Process" resource-kind literal back to lowercase (or off crate::PROCESS_KIND entirely, bypassing the routing pin at [tests::error_ctx_routes_kind_slot_through_process_kind_owner], which binds the Kind slot to that pub const as the ONE workspace-wide owner of the tatara Process CRD’s kind: slot), dropped the qualified-ref routing, or narrowed the accepted verb set to a hardcoded closed set surfaces at process_api::tests::error_ctx_* rather than as silent operator- facing skew across the two consumer sites).