Skip to content
This repository has been archived by the owner on Aug 16, 2021. It is now read-only.

Problems with foreign_links #38

Closed
golddranks opened this issue Sep 12, 2016 · 2 comments
Closed

Problems with foreign_links #38

golddranks opened this issue Sep 12, 2016 · 2 comments

Comments

@golddranks
Copy link
Contributor

First of all, it seems that the order of the blocks in error_chain! { } matters (placing foreign_links after errors made it break). This feels different from the general top-level declarations in Rust so I was surprised. Can the macro be made flexible about the order of the declarations?

Secondly, and more importantly, I'm still unable to get it work :( I have code like this:

pub mod errors {
    error_chain! {
        foreign_links {
            diesel::result::Error, DieselError;
        }
        errors {
            NoSuchUser(email: String) {
                description("No such user exists")
                display("No user with e-mail address {} exists.", email)
            }
            EmailAddressTooLong {
                description("E-mail address too long")
                display("A valid e-mail address can be 254 characters at maximum.")
            }
            AuthError {
                description("Can't authenticate user")
                display("Username (= e-mail) or password doesn't match.")
            }
        }
    }
}

use errors::*;

The foreign links section breaks:

error[E0433]: failed to resolve. Use of undeclared type or module `diesel::result`
  --> src/lib.rs:29:13
   |
29 |             diesel::result::Error, DieselError;
   |             ^^^^^^^^^^^^^^^^^^^^^ Use of undeclared type or module `diesel::result`
<error_chain macros>:119:1: 124:37 note: in this expansion of error_chain! (defined in <error_chain macros>)
<error_chain macros>:133:1: 138:37 note: in this expansion of error_chain! (defined in <error_chain macros>)
src/lib.rs:27:5: 61:6 note: in this expansion of error_chain! (defined in <error_chain macros>)

But I have extern crate diesel; in place, so fully qualified paths starting with diesel should work, right? And trying to address the error message with use diesel::result; or use diesel::result::Error; doesn't help. What to do?

@brson
Copy link
Contributor

brson commented Sep 13, 2016

Thanks for the report @golddranks.

Can the macro be made flexible about the order of the declarations?

I suspect it can, but it would need to be done by a more expert macrologist than I. Here's an issue #41.

But I have extern crate diesel; in place, so fully qualified paths starting with diesel should work, right? And trying to address the error message with use diesel::result; or use diesel::result::Error; doesn't help. What to do?

These paths will be resolved in the scope of the errors mod you have defined, but the extern crate diesel import only brings the diesel name into the top level of the crate; so either prefixing that path with ::, as in ::diesel::result::Error, or adding use diesel to the inside of the mod errors declaration should fix the resolution error.

@Yamakaky
Copy link
Contributor

Closing for #41

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants