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
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.
A bit of background here, the assertion in question was added in https://github.com/emberjs/ember.js/pull/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:
To either:
assert
, if not then throw e
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.
In my case it was duplicate action names