rust-lang-deprecated / error-chain

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

no rules expected this token in macro call #299

Closed TornaxO7 closed 3 years ago

TornaxO7 commented 3 years ago

Hello! I have this example code:

use error_chain::error_chain;

error_chain! {
    errors {
        ParseMail

        // An error appeared, when it tried to parse the body of the mail!
        ParseBody() {
            description("Couldn't get the body of the parsed mail."),
            display(""),
        }
    }
}

fn main() {
}

If I run cargo check then I'm getting the following error message:

error: no rules expected the token `=>`
  --> src/main.rs:3:1
   |
3  | / error_chain! {
4  | |     errors {
5  | |         ParseMail
6  | |
...  |
12 | |     }
13 | | }
   | |_^ no rules expected this token in macro call
   |
   = note: this error originates in the macro `impl_error_chain_kind` (in Nightly builds, run
with -Z macro-backtrace for more info)

What am I doing wrong?

TornaxO7 commented 3 years ago

I've also tried this as shown in the quickstart.rs:

#[macro_use]
extern crate error_chain;

error_chain! {
    errors {
        ParseMail

        ParseBody() {
            description("Couldn't get the body of the parsed mail."),
            display(""),
        }
    }
}

fn main() {
}

but I'm getting the same error message.

TornaxO7 commented 3 years ago

Ok, it was due to the empty brackets (()). Removing them like this:

error_chain! {
    errors { 
        ParseMail

        // An error appeared, when it tried to parse the body of the mail!
        ParseBody {
            description("Couldn't get the body of the parsed mail."),
            display(""),
        }

        /// An error appeared, when it tried to parse/get an attachment!
        ParseAttachment

        ParseFetch

        ForgotHeader(missing_header: String) {
            description(
                concat![
                "Couldn't parse the mail to a sendable mail ",
                "because a header is missing."
            ]),
            display("Missing header: '{}'", missing_header),
        }
    }
}

works.