error-chain
error-chain copied to clipboard
Unexpected token ERROR_CHECK
I get an error from error_chain!{} which origins outside of my crate:
error: no rules expected the token `ERROR_CHECK`
--> lib/core/libimagstore/src/error.rs:20:1
|
20 | / error_chain! {
21 | | types {
22 | | StoreError, StoreErrorKind, ResultExt, Result;
23 | | }
... |
293 | | }
294 | | }
| |_^
|
= note: this error originates in a macro outside of the current crate
error: Could not compile `libimagstore`.
Can you explain this? Here is the code which triggers it!
You have an additional }
Nope, that's just the error message. If you look at the code, it hasn't. Above, the closing } is from the errors {, which is removed by the compiler in the error message (the line with the ...).
Hum, seems like a bug.
error_chain! {
errors {
ConfigurationError {
description("Store Configuration Error"),
}
}
}
If I remove the trailing comma, it works. It should work either way. Do you want to try a PR?
I guess I won't be able to solve this in the error_chain codebase without putting a few hours into it... so I'd prefer if you (or someone from the error_chain project) could tackle this.
For documentation: In my code, I call the error_chain!{} macro from another macro and (as far as I know) cannot remove the trailing comma therefor. But (as far as I understand) this trailing comma triggers a bug in error_chain!{} so the compilation of my code fails.
I reproduced this using a very pared down version of the example from the docs. Only declaring one ErrorKind seems to work, but the second one causes the macro error
error: no rules expected the token `ERROR_CHECK`
Steps to reproduce:
-
Create a new library project with Cargo
-
Add the dependency
error-chain = "0.10.0" -
replace lib.rs with this gist
Cargo.lock shows:
[[package]]
name = "error-chain"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"backtrace 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
I'm very new to error-chain (and Rust macros in general) and am not 100% sure that the test-case I've given should work, or did in the past. I could try to bisect it though -- there's not a ton of hobby time in my schedule but possibly Wednesday.
The fix is actually pretty simple: Remove the trailing , on https://gist.github.com/glasswings/27fcafe631b8bc3b5db9b3602b98840d#file-lib-rs-L12 and the following line.
The error message, though, is really questionable at best :smile:
That's the trouble with complex macros...