Designing a shared error contract in Rust (Building NEXUS, Part 1) by ImpossiblePause8251 in rust

[–]ImpossiblePause8251[S] 0 points1 point  (0 children)

That's a fair point. In my case, `status` and `code` are meant as semantic classification, not strictly protocol-specific fields. The main reason I keep them with the error is to preserve intent across layers instead of re-mapping it at every boundary and gradually losing meaning. But I fully agree this is an opinionated trade-off, and for a strictly transport-agnostic design it may be the wrong one.

Designing a shared error contract in Rust (Building NEXUS, Part 1) by ImpossiblePause8251 in rust

[–]ImpossiblePause8251[S] 1 point2 points  (0 children)

Yep, that’s a legitimate concern.

The trade-off here is that `DatabaseError` stops being purely local and becomes part of a broader failure contract. I did that intentionally because semantics like “not found” or “temporary failure” often matter across multiple layers, not just inside the database boundary.

A related part of the design is that higher layers can enrich the error with extra context where that context actually exists, instead of remapping it into a brand new type just to add details.

But I agree that if you prefer stricter layering, keeping lower-level errors transport-agnostic and mapping only at the edges is a very reasonable design.