DEV Community

Cover image for Your Error Survived the Wrapper. Did Its Code Survive the Trace?

Your Error Survived the Wrapper. Did Its Code Survive the Trace?

Raju Dandigam on November 20, 2026

Suppose an instrumented operation throws an error with code: "ETIMEDOUT". Your application catches that exact object. Its retry policy behaves corr...
Collapse
 
johnnylemonny profile image
𝗝𝗼𝗡𝗻 •

Great breakdown of the gap between runtime error identity and persisted trace fidelity. It is surprisingly easy for an instrumentation wrapper to pass behavioral retry tests on error.code while silently dropping that exact field during serialization, which usually only surfaces later when offline reports lump real timeouts into "unknown" or push teams into parsing brittle error messages.

The point about avoiding a naive full-object dump and verifying an explicit allowlist with a negative fixture for sensitive fields is especially practical. Separating those two contracts upfront saves a lot of silent observability debt.

Collapse
 
raju_dandigam profile image
Raju Dandigam Google Developer Experts •

Thanks, @johnnylemonny. That is exactly the failure mode: a retry test can pass while the readback contract quietly fails. I like pairing the known-code assertion with a synthetic sensitive field that must not survive serialization; it makes both fidelity and the privacy boundary testable. Have you run into an SDK error where a bounded field other than code was essential for diagnosis?

Collapse
 
johnnylemonny profile image
𝗝𝗼𝗡𝗻 •

Definitely. HTTP status codes and provider-specific request IDs (like statusCode or requestId in AWS or OpenAI SDK errors) are essential when code alone is too broad, such as distinguishing a transient 429 rate limit from a hard 403 or tracing a specific failure with support. Keeping a bounded allowlist for fields like status, retryable, and requestId gives you actionable diagnostics without risking payload or header leaks.

Thread Thread
 
raju_dandigam profile image
Raju Dandigam Google Developer Experts •

@johnnylemonny That is a useful distinction: a bounded status or retryable flag can help classify a 429, while a request ID is mainly for correlation with provider support. I would keep those fields on an explicit allowlist, cap their length, and assert both what survives and what is excluded after persisted readback. Thanks for the concrete examples.

Collapse
 
robertpaschal profile image
Odinaka Robert Nnamani •

The ETIMEDOUT example makes this concrete. The retry policy can pass in the app while the persisted trace quietly loses the code it needs, so the allowlist plus negative fixture approach feels like the right call.

Collapse
 
raju_dandigam profile image
Raju Dandigam Google Developer Experts •

@robertpaschal Exactly. I would make the negative fixture as explicit as the known-code assertion: attach a fake sensitive header to the synthetic error, then verify the persisted trace omits it. Otherwise a fidelity fix can quietly expand what traces retain.

Collapse
 
robertpaschal profile image
Odinaka Robert Nnamani •

That fixture is the test. If the trace still carries the header, the fix made things worse.

Collapse
 
alexshev profile image
Alex Shev •

Error preservation needs a contract test at every boundary, including serialization and storage. I would assert the stable machine fields separately from display text, then run the same fixture through the logger, queue, and trace exporter. That catches the cases where a stack remains visible but the code used for routing disappears.

Collapse
 
aheadkit profile image
AheadKit •

The table is the whole piece for me β€” both paths rethrow the same object, but the manual path drops error.code while keeping the message, which is backwards, since the message is the unstable part. And the two paths don't even agree on schema version, 0.1 against 1.0. Do traces from both paths ever land in the same report, and if they do, how do you stop the 0.1 rows from silently classifying every timeout as unknown?

Collapse
 
raju_dandigam profile image
Raju Dandigam Google Developer Experts •

@aheadkit I would treat schema 0.1 as lacking that field by contract and classify it as unavailable, rather than as a genuine unknown error code. If both paths feed one report, keep schema version on every row, split counts by capture path, and never infer error.code from message text. The mismatch remains a compatibility gap to fix, not something reporting should hide.

Collapse
 
prascli profile image
Indra Prasetya •

In agentdiet 0.11, 94 % of CI integrations consume --json rather than text, so the CLI's output contract β€” including error codes β€” is part of the agent's effective capability, not just the model. A missing error.code in the trace means 94 % of automated consumers lose the classification they rely on for retry policies and alerting.

Collapse
 
raju_dandigam profile image
Raju Dandigam Google Developer Experts •

That JSON consumer angle is useful, @prascli. A CLI schema can become an operational dependency even when the human-readable output looks fine. I would test the installed CLI end to end with a known error code, then fail CI if its JSON readback drops or renames the field. In agentdiet, do those consumers mainly use codes for retry decisions, alert grouping, or both?

Collapse
 
code_in-the_margins profile image
Code In The Margins •

The distinction between runtime error preservation and persisted evidence fidelity is important. One additional concern is schema compatibility. If different instrumentation paths persist different schema versions and diagnostic fields, downstream consumers may need to distinguish between an actual absence of an error code and a field that was never captured.
Would you consider schema-version compatibility and field availability part of the same contract, especially when traces from multiple capture paths feed the same reporting pipeline?

Collapse
 
raju_dandigam profile image
Raju Dandigam Google Developer Experts •

@code_in-the_margins Yes. Schema version and field availability belong in the readback contract: a missing code on a 0.1 manual row means it was not captured, while a missing code on a 1.0 row may mean the error had no code. A mixed report should preserve that distinction explicitly; otherwise it turns a serialization gap into a misleading error category.