insta
insta copied to clipboard
Adding context to glob! on panic
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
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...)
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?