rust-lang-deprecated / error-chain

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

Unexpected token ERROR_CHECK #214

Open matthiasbeyer opened 7 years ago

matthiasbeyer commented 7 years ago

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!

Yamakaky commented 7 years ago

You have an additional }

matthiasbeyer commented 7 years ago

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

Yamakaky commented 7 years ago

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?

matthiasbeyer commented 7 years ago

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.

jClaireCodesStuff commented 7 years ago

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:

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.

matthiasbeyer commented 7 years ago

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:

Yamakaky commented 7 years ago

That's the trouble with complex macros...