Comments (15)
I think re-exporting color-backtrace's configuration with an install method that handles both makes a lot of sense.
from color-eyre.
Sorry, I wrote that wrong...
What I meant was that color-eyre
could implement its own panic handler instead of calling the color-backtrace
install method. Then it doesn't matter that color-backtrace
's install takes the BacktracePrinter by value since you wouldn't call it.
(You figured out how to solve the cloning issues as I was typing it up, so its certainly not as compelling a solution now)
from color-eyre.
This sounds like a great idea, thank you! I'm thinking the best way to do this would be to add a static variable for storing custom filters and some functions for manipulating this global filter set which you can call at the beginning of main to setup your custom filters. Would that work for you? It would add a global RWLock that has to be read from every time format a Report but given the fact that error reporting probably isnt in the critical path I'm guessing this is a good tradeoff.
from color-eyre.
Well, there are other options on color_backtrace as well: color scheme, message, etc. It seems to me that a user might want to configure those as well. So maybe not an api that only allows setting frame filters? (I don't need more then that... but maybe somebody does).
I think the ideal API would be to get a function added to color_backtrace
that returns the currently installed BacktracePrinter. Then whatever settings are put in to the color_backtrace install automatically apply to eyre-color.
Perhaps a slightly less ideal api would be a static variable in eyre-color that stores the current backtrace printer with some sort of install function to set it. Then I'd just install my backtrace printer into both color_backtrace and eyre-color.
from color-eyre.
Aah yea fair, one thing I'm worried about is that by making ourself dependent upon the API of color-backtrace we'd have to make a breaking change every time they do. That said, it may be worth it to couple them together, I doubt any breaking changes made in color-backtrace would be disruptive, if it even happens any time soon.
Maybe we should just reexport the configuration and install part of color-backtrace
's API such that calling install
with a color_eyre::BacktracePrinter
sets up both the panic printer and the Report backtrace printer. This wouldn't even require adding a method to access the global BacktracePrinter in color-backtrace
.
This will also require some updates to color-spantrace
so that it uses the same color pallet as color-backtrace
when a custom printer is installed.
cc @athre0z
from color-eyre.
It looks like BacktracePrinter
isn't Clone
, so we will have to fix that before we can reuse a BacktracePrinter
in two places.
Edit: oof, it can't be made clone without making a breaking change to the callback type :((((((
Edit 2: the callback is an Fn trait object so I cannot add a Clone
bound to it 🙃
Edit 3: Arc<T>
impls From<Box<T>>
, victory!
from color-eyre.
Alternatively:
color-eyre will have to maintain a static variable holding the BacktracePrinter.
Instead of calling color_eyre's install, it should install its own panic handler that fetches the BacktracePrinter from from the static variable. Then there is no need to clone the BacktracePrinter.
from color-eyre.
@winstonewert color-backtrace's install
method takes the BacktracePrinter
by value so you cannot install it into a static defined in color-eyre
and the global panic printer at the same time. If I'm understanding you right that you mean to call install on color-backtrace
and color-eyre
separately that would work but I don't think it's a great API.
I think I'd rather wait until the PR to make BacktracePrinter
Clone merges. areth0z is normally extremely responsive so I bet they will merge it as soon as they wake up. That way I can provide the single configure + install interface from color-eyre
.
from color-eyre.
But to throw another wrench in things, it occurs to me that you might not want exactly the same settings between panicing and errors. In particular, I suspect that the desired panic message is different then the desired error message for many people.
from color-eyre.
hmm, yea. I wonder if calling color_backtrace::install after you've already installed a panic printer works fine. Hopefully yes, that at least would let people separately call the second install method to get the different setup.
I have another wrench as well, BacktracePrinter doesn't expose the colorscheme as part of its API, only a setter method, so I cannot look inside of a BacktracePrinter
to see what colors it has configured so that the SpanTrace / error messages / help text highlighting is updated to match. I'll tenatively open a PR to add an accessor method to retrieve a reference to the internal ColorScheme I guess...
from color-eyre.
I think I'm going to timebox this, I'm going to provide an initial API for setting the backtrace printer just for color-eyre
. I'm not gonna bother with the also set color-backtrace
's printer or with the be consistent with coloring changes as part of this issue, that way at least you can promptly get your custom frame filtering. It should be easy enough to add the extra features later when people end up needing them without making breaking changes.
from color-eyre.
@winstonewert I've pushed an implementation of the change with #17, can you test it out and lmk if it works for you before I go ahead and merge it / make a new release.
[patch.crates-io]
color-eyre = { git = "https://github.com/yaahc/color-eyre.git", branch = "filters" }
from color-eyre.
Worked great.
from color-eyre.
Alright, v0.3.2
should be good to go with the filter feature setup. Thanks again for the suggestion!
from color-eyre.
Thanks!
from color-eyre.
Related Issues (20)
- Outdated documentation about color-backtrace
- How to access fields of a Report
- Attach Report's to an error via Section::error()
- Report creation takes a lock HOT 3
- Print a backtrace/spantrace to debug logs not to stderr HOT 1
- panic in tests (I used master) HOT 1
- Is there an easy way to make custom errors have equivalent report functions HOT 1
- show sections when panic macro is called HOT 1
- Output has few/no colors in Gnome Terminal
- should info! events be captured and printed as part of the SpanTrace? HOT 1
- Mechanism to add sections in hook callback
- Omit numbering of errors if there's only one HOT 2
- color-eyre uses the same inexplicable information order as standard backtraces HOT 1
- Automate synchronization between docs.rs and README.md
- Disable setting panic hook HOT 2
- Ergonomics: Full re-exports from `eyre`; export `color_eyre::eyre!` macro, rather than `eyre` crate HOT 2
- Add a config option to print panic output to stdout.
- First eyre::Result::Err variant is slow to construct if backtraces are enabled
- Construct a new `Handler` after already having created one / modify handler HOT 1
- Wrap types so we don't have to re-export `owo_colors` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from color-eyre.