shepmaster / snafu

Easily assign underlying errors into domain-specific errors while adding context
https://docs.rs/snafu/
Apache License 2.0
1.45k stars 61 forks source link

Add support for `#[track_caller]` #247

Closed shepmaster closed 3 years ago

shepmaster commented 4 years ago

This will involve adding a feature flag for Rust 1.46, then adding #[track_caller] to the context selector methods like build and fail.

ctaggart commented 4 years ago

I found the RFC at https://github.com/rust-lang/rfcs/pull/2091. I think this is what I'm looking for. Yesterday, I ended up sprinkling code like this everywhere:

        let typ = ident(&alias_name.to_camel_case()).context(IdentError {
            file: file!(),
            line: line!(),
        })?;

It would be great if there was a variable like source that captured the caller automatically.

shepmaster commented 4 years ago

captured the caller automatically.

I have doubts about the true value of this. Why do you reuse an error type so frequently? Concretely speaking, why do you use IdentError in so many places that the file / line location is required to be able to make sense of a resulting error? If each context selector is used once, its name is already a unique identifier to locate the exact location of the problem.

ctaggart commented 4 years ago

Thanks @shepmaster. I'd like to get to a point where each one is uniquely named, but it was easiest at first to wrap an error type generically. Well, until the error was thrown and I couldn't figure out the location.

shepmaster commented 3 years ago

Closed via #247