6

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
Community
  • 1
  • 1
swrobel
  • 4,053
  • 2
  • 33
  • 42

2 Answers2

1

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'
MilesStanfield
  • 4,571
  • 1
  • 21
  • 32
  • 1
    Thanks for the answer, but unfortunately my backtraces don't look like that. I've edited the question to include the first line of the backtrace in case that helps. It just continues through the gem stack from there, with no reference to filenames in my project. – swrobel Dec 24 '15 at 16:50
1

One workaround is to compile your .coffee files yourself outside of rails to get a decent error message. See https://stackoverflow.com/a/41700235/1836506

Community
  • 1
  • 1
Eric Simonton
  • 5,702
  • 2
  • 37
  • 54