Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails asset pipeline doesn't indicate which file produced an error

I cannot for the life of me figure out how to get Sprockets to indicate which file caused a compilation error. I simply get errors like the following:

CoffeeScript

Completed 500 Internal Server Error in 14671ms (ActiveRecord: 281.4ms)

ExecJS::RuntimeError - SyntaxError: [stdin]:1:5: unexpected ,:
  execjs (2.6.0) lib/execjs/external_runtime.rb:84:in `extract_result'
<backtrace continues>

Which can be triggered by adding the following to invalid syntax to an included .coffee file:

test,

Sass

Completed 500 Internal Server Error in 14671ms (ActiveRecord: 281.4ms)

Sass::SyntaxError - Invalid CSS after "0": expected expression (e.g. 1px, bold), was ";":
  sass (3.4.20) lib/sass/scss/parser.rb:1179:in `expected'
<backtrace continues>

Which can be triggered by adding the a semicolon to a .sass file like so:

.test
  top: 0;

In the case of warnings, the server logs show something helpful like

WARNING on line 9 of /path/to/file.sass: This selector doesn't have any properties and will not be rendered.

However, syntax errors simply seem to render a 500 error and tell me the line & column of the error, but not which file it was in. I've dug through the backtraces and they don't give any indication of the file in which the error occurred. How can I get the output to show the file in which the SyntaxError occurred?

Versions (everything latest as of this writing):

  • Rails 4.2.5
  • Sprockets-Rails 3.0.0
  • Sprockets 3.5.2
  • Sass-Rails 5.0.4
  • Sass 3.4.20
  • Coffee-Rails 4.1.0
  • Coffee-Script 2.4.1
  • Coffee-Script-Source 1.10.0
like image 567
swrobel Avatar asked Dec 23 '15 20:12

swrobel


1 Answers

Keep reading that 500 error in your server. It should show the file and the line of the file that caused the error. Example below says app/assets/stylesheets/test.sass:2

Completed 500 Internal Server Error in 152ms (ActiveRecord: 0.0ms)

ActionView::Template::Error (Invalid CSS after "0": expected expression (e.g. 1px, bold), was ";"):
    2: <html>
    3: <head>
    4:   <title>StackoverflowQuestions</title>
    5:   <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
    6:   <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
    7:   <%= csrf_meta_tags %>
    8: </head>
  app/assets/stylesheets/test.sass:2
  app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb__1109435584510058936_70275420820360'
like image 197
MilesStanfield Avatar answered Sep 24 '22 11:09

MilesStanfield