rust-lang-deprecated / error-chain

Error boilerplate for Rust
Apache License 2.0
730 stars 111 forks source link

error_chain does not escape {} in description() #230

Closed fschutt closed 6 years ago

fschutt commented 7 years ago

https://play.rust-lang.org/?gist=5091717006ad7e3c32358f236b4e3459&version=stable

If you omit the {} in the formatting string, it will work correctly. {} is only allowed in display, which is not documented (as far as I can see). Is this intentional?

The error:

error: no rules expected the token `TUPLE`
  --> src/errors.rs:3:1
   |
3  | / error_chain! {
4  | |     
5  | |     foreign_links {
6  | |         IoError(::std::io::Error);
...  |
28 | |     }
29 | | }
   | |_^
   |
   = note: this error originates in a macro outside of the current crate

error: aborting due to previous error

... is fairly cryptic. It may be useful to either put a warning into the docs or let description accept a formatting string, like display for consistency.

Yamakaky commented 7 years ago

It's correct. It matches https://doc.rust-lang.org/std/error/trait.Error.html#tymethod.description, which returns a &str.

fschutt commented 7 years ago

I know the cause. However, I don't see why error_chain has to stick with the std::Error here. Notice, that the description method does not require the &str to be 'static. It could take a Formatter instead (which would not break any existing code), so that you could print some dynamic value in the description. The upside to this would be that you don't get a cryptic error anymore. The downside would be ... performance? But then again, printing errors is not something you do very often.

fschutt commented 6 years ago

Well it's a design problem in my view. Closing because it's not really a bug, however it should be kept for Google searches.