tricknotes / ember-cli-rails

Unify your EmberCLI and Rails Workflows
http://thoughtbot.github.io/ember-cli-rails/
MIT License
712 stars 205 forks source link

The error message displayed when compiling a template, doesn't contain location / file information #318

Open kozak opened 8 years ago

kozak commented 8 years ago

I had an error in a handlebars template (there is a href="#" and also a binding to href):

{{#link-to "staff" tagName="li" }}
    <a href="#"  {{bind-attr href="view.href"}}>Test </a>
{{/link-to}}

The error I got, didn't include the file information that is normally included in ember build This is what was displayed:

Error: Assertion Failed: You cannot set `href` manually and via `{{bind-attr}}` helper on the same element.
  at new Error (native)
  at Error.EmberError (adminr/bower_components/ember/ember-template-compiler.js:4064:21)
  at Object._emberMetalCore.default.assert (adminr/bower_components/ember/ember-template-compiler.js:169:13)
  at assertAttrNameIsUnused (adminr/bower_components/ember/ember-template-compiler.js:11766:38)
  at TransformBindAttrToAttributes.assignAttrs (adminr/bower_components/ember/ember-template-compiler.js:11662:7)
  at adminr/bower_components/ember/ember-template-compiler.js:11646:20
  at Walker.visit (adminr/bower_components/ember/ember-template-compiler.js:18302:7)
  at visitors.Program (adminr/bower_components/ember/ember-template-compiler.js:18312:16)
  at Walker.children (adminr/bower_components/ember/ember-template-compiler.js:18335:7)
  at Walker.visit (adminr/bower_components/ember/ember-template-compiler.js:18303:12)
  at visitors.BlockStatement (adminr/bower_components/ember/ember-template-compiler.js:18323:14)
  at Walker.children (adminr/bower_components/ember/ember-template-compiler.js:18335:7)
  at Walker.visit (adminr/bower_components/ember/ember-template-compiler.js:18303:12)
  at visitors.Program (adminr/bower_components/ember/ember-template-compiler.js:18312:16)
  at Walker.children (adminr/bower_components/ember/ember-template-compiler.js:18335:7)
  at Walker.visit (adminr/bower_components/ember/ember-template-compiler.js:18303:12)
  at visitors.BlockStatement (adminr/bower_components/ember/ember-template-compiler.js:18323:14)
  at Walker.children (adminr/bower_components/ember/ember-template-compiler.js:18335:7)
  at Walker.visit (adminr/bower_components/ember/ember-template-compiler.js:18303:12)
  at visitors.ElementNode (adminr/bower_components/ember/ember-template-compiler.js:18318:16)
  at Walker.children (adminr/bower_components/ember/ember-template-compiler.js:18335:7)
  at Walker.visit (adminr/bower_components/ember/ember-template-compiler.js:18303:12)
  at visitors.ElementNode (adminr/bower_components/ember/ember-template-compiler.js:18318:16)
  at Walker.children (adminr/bower_components/ember/ember-template-compiler.js:18335:7)
  at Walker.visit (adminr/bower_components/ember/ember-template-compiler.js:18303:12)
  at visitors.Program (adminr/bower_components/ember/ember-template-compiler.js:18312:16)
  at Walker.children (adminr/bower_components/ember/ember-template-compiler.js:18335:7)
  at Walker.visit (adminr/bower_components/ember/ember-template-compiler.js:18303:12)
  at visitors.BlockStatement (adminr/bower_components/ember/ember-template-compiler.js:18323:14)
  at Walker.children (adminr/bower_components/ember/ember-template-compiler.js:18335:7)
  at Walker.visit (adminr/bower_components/ember/ember-template-compiler.js:18303:12)
  at visitors.Program (adminr/bower_components/ember/ember-template-compiler.js:18312:16)
  at Walker.children (adminr/bower_components/ember/ember-template-compiler.js:18335:7)
  at Walker.visit (adminr/bower_components/ember/ember-template-compiler.js:18303:12)
  at TransformBindAttrToAttributes_transform [as transform] (adminr/bower_components/ember/ember-template-compiler.js:11639:12)
  at Object.preprocess (adminr/bower_components/ember/ember-template-compiler.js:17693:27)
  at compileSpec (adminr/bower_components/ember/ember-template-compiler.js:12791:37)
  at Object.exports.default [as precompile] (adminr/bower_components/ember/ember-template-compiler.js:12705:12)
  at Object.module.exports.template (adminr/node_modules/ember-cli-htmlbars/utils.js:29:40)
  at TemplateCompiler.processString (adminr/node_modules/ember-cli-htmlbars/index.js:68:36)
  at adminr/node_modules/ember-cli-htmlbars/node_modules/broccoli-persistent-filter/lib/strategies/persistent.js:35:42
  at lib$rsvp$$internal$$tryCatch (adminr/node_modules/ember-cli-htmlbars/node_modules/broccoli-persistent-filter/node_modules/rsvp/dist/rsvp.js:493:16)
  at lib$rsvp$$internal$$invokeCallback (adminr/node_modules/ember-cli-htmlbars/node_modules/broccoli-persistent-filter/node_modules/rsvp/dist/rsvp.js:505:17)
  at lib$rsvp$$internal$$publish (adminr/node_modules/ember-cli-htmlbars/node_modules/broccoli-persistent-filter/node_modules/rsvp/dist/rsvp.js:476:11)
  at lib$rsvp$asap$$flush (adminr/node_modules/ember-cli-htmlbars/node_modules/broccoli-persistent-filter/node_modules/rsvp/dist/rsvp.js:1198:9)
  at process._tickCallback (node.js:355:11)

When I run ember build I get a huge stack trace (which also includes deprecation information) and the file name:

Build failed.
File: adminr/templates/application.handlebars
Assertion Failed: You cannot set `href` manually and via `{{bind-attr}}` helper on the same element.
seanpdoyle commented 8 years ago

Thanks for opening this issue and bringing this to our attention!

This behavior is odd. The gem doesn't do anything with the ember-cli generated error / stack trace.

The way we handle inter process communication between rails s and ember b --watch is by depending on EmberCLI to write build errors to STDERR, which we redirect to an error file that Rails is watching.

Outside of that, we don't have any logic around including / excluding error messages or stack traces.

TL;DR:

What version of Ember CLI are you using?

What version of the gem are you using?

What version of the addon are you using?

On the surface, this sounds like a bug in the way EmberCLI writes errors.

kozak commented 8 years ago

Thanks for a speedy reply, sorry for not including this information in the first place: package.json: ember-cli: 1.13.13 ember-cli-rails-addon: "^0.5.2"

gem: most recent version from github, from Gemfile.lock

GIT
  remote: git@github.com:thoughtbot/ember-cli-rails.git
  revision: 7badc2581e0158bb8017cf5a24a39ea8d50b77df
  specs:
    ember-cli-rails (0.5.6)
      cocaine (~> 0.5.0)
      non-stupid-digest-assets (~> 1.0.0)
      railties (>= 3.2, < 5)
      sprockets (>= 2.0)

When doing:

%node_modules/ember-cli/bin/ember b app/app.js 2>errors.txt
version: 1.13.13
Build failed.

the generated errors.txt includes the file information, here is the output: errors.txt

seanpdoyle commented 8 years ago

@kozak would you mind pulling down https://github.com/thoughtbot/ember-cli-rails/pull/324 and seeing if that corrects this issue?

kozak commented 8 years ago

Bad news: Unfortunately, it doesn't. Good news: it appears that Ember creates its own tmp/error.txt file that overwrites the one Ember cli rails is creating from stderr redirection. If I change the error file name here https://github.com/thoughtbot/ember-cli-rails/blob/master/lib/ember_cli/path_set.rb#L75 to be something different than error.txt the whole information is preserved in the log.

This also includes deprecations, so the first backtrace will not necessary be the actual ERROR. I am working on a Pull request.

kozak commented 8 years ago

@seanpdoyle How do you want to approach filtering out deprecations from the error file ?

seanpdoyle commented 8 years ago

Unfortunately, tmp/error.txt isn't an EmberCLI generated file. The file is generated by the ember-cli-rails-addon addon.

When the gem executes the ember build --watch command, the addon's error monitoring gets clobbered by redirecting STDERR to tmp/error.txt (and vice versa).

To correct this, we can change how the addon behaves.

Unfortunately, this fix is blocked by EmberCLI writing DEPRECATION warnings to STDERR.

Once a fix for that improper behavior lands, we can merge https://github.com/rondale-sc/ember-cli-rails-addon/pull/24

seanpdoyle commented 8 years ago

@kozak bad news: there isn't a good approach to prevent writing DEPRECATION warnings to STDERR.

good news is that @rwjblue has written https://github.com/rwjblue/ember-cli-template-lint, which delays throwing deprecation warnings, pushing them out of build tools and into the browser.

Would you mind adding that addon in combination with https://github.com/rondale-sc/ember-cli-rails-addon/pull/24?

If that works for you, I could merge and release, documenting the new dependency.

kayakyakr commented 8 years ago

Tangentially related, I received:

[BABEL] Note: The code generator has deoptimised the styling of "/home/templates..." as it exceeds the max of "100KB".

Which is a warning of a stupidly long template, but causes the rails server to throw an error even though the build was technically successful. This is with https://github.com/rondale-sc/ember-cli-rails-addon/pull/24

kozak commented 8 years ago

@seanpdoyle Sorry for getting back so late. Your suggested setup works fine and displays the correct error message!

seanpdoyle commented 8 years ago

@kayakyakr addressed in https://github.com/babel/babel/pull/3156

seanpdoyle commented 8 years ago

@kayakyakr according to to maintainer of Babel:

This is an error though. You shouldn't be passing such large files to the code generator as it's not currently suited for it. There's no stack trace because it's useless as the call stack depth is already too deep to show any useful debugging information.

https://github.com/babel/babel/pull/3156#issuecomment-163938591

kayakyakr commented 8 years ago

I've stopped receiving the error, though, so I can't dig deeper right now...

The worst thing is that it's coming from a handlebars template that's around 10k in size. A 250 line, 8000 character template explodes into a 99,000 character js file. Yikes.