eyre-rs / color-eyre

Custom hooks for colorful human oriented error reports via panics and the eyre crate
Other
958 stars 57 forks source link

fix: Do not panic on multiple `install` calls #114

Closed jaysonsantos closed 2 years ago

jaysonsantos commented 2 years ago

When writing tests it is really useful to use color-eyre to have better messages but, calling install multiple times will panic. This should return an error instead. It should fix #97

jaysonsantos commented 2 years ago

I wonder if it would be better to use sync::Once on color_eyre::install to make sure only one instance is being installed using a singleton, what do you think? let me know and i can change the pr

yaahc commented 2 years ago

I think I prefer this version as is over doing it in a Once. It's easy enough^1 to write a wrapping function using a Once if you're going to intentionally race a bunch of installs, and in my experience color-eyre isn't the only library where you need to worry about initializing it once in tests so leaving that to the user seems like the right balance to me.

jaysonsantos commented 2 years ago

@yaahc cool! Then, I just sent the fix for the example as I only ran a simple cargo test here

yaahc commented 2 years ago

I updated an error message and I think it's gonna break fmt :X

edit: it didn't! Easyyyyy

jaysonsantos commented 2 years ago

this also seems to fix #78