insta icon indicating copy to clipboard operation
insta copied to clipboard

Adding context to glob! on panic

Open nyurik opened this issue 2 years ago • 2 comments

In case my code panics in this common pattern, it is somewhat difficult to figure out which original file has caused the failure. Would it be possible for glob! to use catch_unwind and report the file being processed?

glob!("../tests/fixtures", "**/*.txt", |file| {
    // this panic is deep inside the code,
    // without any knowledge of the current file
    panic!("something panicked"); 
});

Expected output

---- my_test stdout ----
while processing `some_path/my_input_file_discovered_by_glob.txt`:
thread 'my_test' panicked at <some_file>:
My error message

nyurik avatar Aug 18 '23 04:08 nyurik

Slightly tangential, but we use description=> to add context to the errors within a glob!:

https://github.com/PRQL/prql/blob/c3ab63acdbd0729f73a18aa420216bc91cc7d2d1/crates/prql-compiler/tests/integration/main.rs#L345-L349

(giving more context automatically sounds like a good idea too though...)

max-sixty avatar Aug 19 '23 07:08 max-sixty

Maybe there could be a flag that controls catching of panics. I think the issue is that the rust testing infrastructure is already pretty brittle as it stands and catching down panics might be a bit too magic?

mitsuhiko avatar Aug 26 '23 22:08 mitsuhiko