Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message when Model doesn't implement Default #376

Closed
MartinKavik opened this issue Feb 27, 2020 · 4 comments
Closed

Improve error message when Model doesn't implement Default #376

MartinKavik opened this issue Feb 27, 2020 · 4 comments
Labels
enhancement New feature or request

Comments

@MartinKavik
Copy link
Member

MartinKavik commented Feb 27, 2020

"... and AfterMount doesn't create Model instance explicitly".

Should we add something like assert somewhere to give the user a reasonable error message?
Ideas?

@familyfriendlymikey
Copy link
Contributor

familyfriendlymikey commented Feb 27, 2020

Here's the error:

error[E0599]: no method named `build_and_start` found for type `seed::app::builder::Builder<Msg, Model, seed::virtual_dom::node::Node<Msg>, seed::app::UndefinedGMsg, seed::app::builder::init::UndefinedInitAPI>` in the current scope
  --> src/lib.rs:35:32
   |
35 |     App::builder(update, view).build_and_start();
   |                                ^^^^^^^^^^^^^^^ method not found in `seed::app::builder::Builder<Msg, Model, seed::virtual_dom::node::Node<Msg>, seed::app::UndefinedGMsg, seed::app::builder::init::UndefinedInitAPI>`
   |
   = note: the method `build_and_start` exists but the following trait bounds were not satisfied:
           `seed::app::builder::init::UndefinedInitAPI : seed::app::builder::InitAPI<Msg, Model, seed::virtual_dom::node::Node<Msg>, seed::app::UndefinedGMsg>`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0599`.

Solved with:

#[derive(Default)]
struct Model {
    data: Data,
    ...
}

#[derive(Default)]
struct Data {
    ...
}

@TatriX
Copy link
Member

TatriX commented Feb 28, 2020

I'm sure I've seen this error before, but right now I'm not sure how can I reproduce it. Could you please add an example?

@MartinKavik
Copy link
Member Author

@TatriX You were asking me about it some time ago if I remember correctly :) How to repro - make sure your Model doesn't impl Default and don't use after_mount.


I did quick research.
I recommend to remove the code that represents the deprecated app builder API as the first step, because it makes code pretty complex.
2nd step: Implement two build_and_start functions. It's not possible directly on Builder so we have to add an extra trait for it. The first function will build and start the app in the standard way, the second one will contain compile_error!("Hey, I don't know how to create Model!").
(I'm not sure if it's doable and the best way, other opinions welcome.)

@MartinKavik MartinKavik added this to the 2. Stable basic Seed API milestone Mar 9, 2020
@MartinKavik MartinKavik added the enhancement New feature or request label Mar 9, 2020
@MartinKavik MartinKavik mentioned this issue Mar 12, 2020
@MartinKavik
Copy link
Member Author

New API for App initialization - #382 - implemented in PR #388. It's much simpler so it should eliminate all cryptic compiler errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants