error-chain icon indicating copy to clipboard operation
error-chain copied to clipboard

Unexpected token ERROR_CHECK

Open matthiasbeyer opened this issue 8 years ago • 7 comments
trafficstars

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!

matthiasbeyer avatar Aug 31 '17 19:08 matthiasbeyer

You have an additional }

Yamakaky avatar Aug 31 '17 20:08 Yamakaky

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 ...).

matthiasbeyer avatar Sep 01 '17 06:09 matthiasbeyer

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?

Yamakaky avatar Sep 01 '17 20:09 Yamakaky

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.

matthiasbeyer avatar Sep 01 '17 20:09 matthiasbeyer

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.

jClaireCodesStuff avatar Sep 03 '17 16:09 jClaireCodesStuff

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:

matthiasbeyer avatar Sep 03 '17 19:09 matthiasbeyer

That's the trouble with complex macros...

Yamakaky avatar Sep 03 '17 21:09 Yamakaky