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

Misleading error on 3.15 migration #18640

Closed
MichalBryxi opened this issue Dec 27, 2019 · 3 comments · Fixed by #19342
Closed

Misleading error on 3.15 migration #18640

MichalBryxi opened this issue Dec 27, 2019 · 3 comments · Fixed by #19342
Labels

Comments

@MichalBryxi
Copy link

MichalBryxi commented Dec 27, 2019

During my Octane migration adventures I stumbled upon this error:

index.js:172 Uncaught Error: Assertion Failed: You attempted to generate a link 
for the "cashbook" route, but did not pass the models required for generating 
its dynamic segments. Assertion Failed: The @action decorator must be 
applied to methods when used in native classes

Screenshot 2019-12-27 at 22 31 47

I got confused on the first part of "generating link", but the main problem is in the "@action decorator". Once I solved this, the error on "cashbook route" went away.

I believe there are two ways to improve the DX:

  1. It looks like that whatever yields the "cashbook route" error (I assume a LinkTo component?) once it catches some exception it wrongly assumes that the models were not provided.
  2. If the second error complaining about @action would give me a hint about the file that was incorrect, I would find the source of the problem much quicker.

Foot note for whoever might suffer from the same issue: I happened to have action and task (from ember-concurrency) defined in one controller with the same names. After running npx ember-native-class-codemod http://localhost:4200 ./app codemod, their names collided in the class-level namespace.

@rwjblue
Copy link
Member

rwjblue commented Feb 11, 2020

A bit of background here, the assertion in question was added in #14554. That fix assumes that the only reason that this may error is that you haven't supplied enough dynamic params (and the reason we augment the error message is that you need to know the target route).

I think the right fix here would be to update this catch block:

} catch (e) {
// tslint:disable-next-line:max-line-length
assert(
`You attempted to generate a link for the "${this.route}" route, but did not ` +
`pass the models required for generating its dynamic segments. ` +
e.message
);
}

To either:

  1. Remove the bit about invalid dynamic segments (so that the message just mentions something like "An error occurred while generating a link
    for the "cashbook" route, ${e.message}"
  2. Check if the error that is actually thrown is the expected one, if it is do the assert, if not then throw e

@rwjblue rwjblue added the Bug label Feb 11, 2020
@devpol91
Copy link

Yup, just had the same issue in 3.18, thanks for posting this, made it easy to see past the generate link bit to the real issue of @action decorator in my case being the same name as another.

@rohitsharmami
Copy link

In my case it was duplicate action names

ef4 added a commit that referenced this issue Jan 18, 2021
kategengler pushed a commit that referenced this issue Jan 19, 2021
This fixes #18640.

(cherry picked from commit e49285a)
sly7-7 pushed a commit to sly7-7/ember.js that referenced this issue Mar 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants