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

Dev mode error for missing loop value #681

Closed
Rich-Harris opened this issue Jun 26, 2017 · 2 comments
Closed

Dev mode error for missing loop value #681

Rich-Harris opened this issue Jun 26, 2017 · 2 comments

Comments

@Rich-Harris
Copy link
Member

This results in an unhelpful error — 'Cannot read property 'length' of undefined':

{{#each missing as thing}}
  <p>{{this}}</p>
{{/each}}

In dev mode, we could check that missing is an array-like object, and give a less cryptic error if not.

@Rich-Harris
Copy link
Member Author

Just had a thought. One of the reasons this error is a bit unhelpful is that it doesn't point back to the source code. So whereas in this situation if foo is undefined, the sourcemap shows us where the problem is...

screen shot 2017-06-27 at 8 52 27 am

...if foo is defined but foo.bar isn't, it doesn't:

screen shot 2017-06-27 at 8 52 42 am

I think we could fix this. If here, and in every other place we access .length, we instead overwrote the each with length and accessed .[✂${a}-${b}✂], where a and b are the start and end positions of the each, then the failed property access would point to the start of each, and clicking on the stack trace in devtools would point you to the offending block.

We should still have the dev mode warning, but this would be a very handy way to get most of the benefits without dev mode.

@Rich-Harris
Copy link
Member Author

It works!

screen shot 2017-06-27 at 11 01 30 am

Opening a PR now

Rich-Harris added a commit that referenced this issue Jun 28, 2017
hack sourcemap to mitigate confusion caused by missing data for each block
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants