Ember.js: Misleading error on 3.15 migration

Created on 27 Dec 2019  ·  3Comments  ·  Source: emberjs/ember.js

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.

Bug

All 3 comments

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:

https://github.com/emberjs/ember.js/blob/d1ad76a2b22ce470639df3dfc6efb6864a70f588/packages/%40ember/-internals/glimmer/lib/components/link-to.ts#L770-L777

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

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

Was this page helpful?
0 / 5 - 0 ratings