3 ms·
This crate is an answer to my debugging prayers, thank you for making it. Is there a feature I can toggle to turn off the stack traces? This is a feature that I
by ryukoposting 3y ago
This crate is an answer to my debugging prayers, thank you for making it. Is there a feature I can toggle to turn off the stack traces? This is a feature that I can see being useful only in development builds for some of my use cases.
- JoelJacobson 3y agoThanks, I'm glad you like it! Not sure what you mean when you say you want to "turn off the stack traces"? There are no implicit stack traces / backtraces. The detailed example in the docs makes use of `.expect()` and `RUST_BACKTRACE=1`, maybe this made you think it always does a backtrace? Here is an example without backtraces, where the debug string is created and printed for the error instead: use wherr::wherr; #[wherr] fn concat_files(path1: &str, path2: &str) -> Result<String, Box<dyn std::error::Error>> { let mut content1 = std::fs::read_to_string(path1)?; let content2 = std::fs::read_to_string(path2)?; content1.push_str(&content2); Ok(content1) } fn main() { let content = concat_files("file1.txt", "file2.txt"); println!("{:?}", content); } % cargo run --example example Compiling wherr v0.1.5 (/Users/joel/src/wherr/wherr) Finished dev [unoptimized + debuginfo] target(s) in 0.15s Running `/Users/joel/src/wherr/target/debug/examples/example` Err(Os { code: 2, kind: NotFound, message: "No such file or directory" } error at wherr/examples/example.rs:5)
- ryukoposting 3y agoAh, I meant "stack traces" in the system sense: Imagine a really deep chain of #[wherr]-marked functions. If I understand the crate's behavior right, when an error occurs in that case, you're effectively constructing a stack trace as that error bubbles up through `?` operators. Now, maybe if the functions return something like Result<_, wherr::Error>, you could collapse those traces, but if you're returning Result<_, Box<dyn Error>>, that isn't possible (barring macro shenanigans).