Why Use Structured Errors in Rust Applications?

home.expurple.me

77 points by todsacerdoti 10 months ago


arccy - 10 months ago

Having had to work with various application written in rust... i find they have some of the most terrible of errors. "<some low level operation> failed" with absolutely no context on why the operation was invoked in the first place, or with what arguments.

This is arguably worse than crashing with a stack trace (at least i can see a call path) or go's typical chain of human annotated error chains.

lifthrasiir - 10 months ago

I recently saw the `error_mancer` crate [1] that automatically generates error types for each function so that error definitions and functions are adjacent to each other. While it wouldn't be sufficient for all cases, I quite liked its approach.

[1] https://crates.io/crates/error_mancer

ozgrakkurt - 10 months ago

You only ever need backtrace with line numbers and error kind enum for library code and app code that is no supposed to fail.

For app code that is supposed to fail, you need full custom error setup.

For example in a a http server you want to cleanly convert error to http response and a record on server side for viewing later.

imo zig implements errors in language pefectly