I am working on a Rails 4 site (Ruby 2.1.2) and using haml (4.0.5) for the site templates.
I have a page with this code:
%section
%h1 Info
%h2 More info
This works fine and the page is displayed. However, if I change it to:
%section#info
%h1 Info
%h2 More info
I get this error:
stack level too deep
And the only trace is:
airbrake (4.0.0) lib/airbrake/rails/middleware.rb:16
This is odd as this path does not exist in my app.
Any ideas on why this change in HAML would cause this error? What does this error mean?
Also what is the best troubleshooting method or approach to track this down on my own?
@analyticspierce, can you try just adding a comment before the tag ID like this:
%section //#info
Save your page, load it, then take the comment away? I tried replicating your problem on a simple view and was unable to create an exception.
If I add that comment I get the following error highlighting the %h1 line below the %section //#info line:
Illegal nesting: content can't be both given on the same line as %section and nested within it
Here is the complete stack trace from the development log. I did have the airbrake gem installed but not setup. I uninstalled the airbrake gem but still get the error.
I think this shows the error message is coming from the airbrake setup but there is still a server error being generated before the airbrake message. Any suggestions or next steps are appreciated.
Started GET "/welcomes" for 127.0.0.1 at 2014-08-23 10:07:28 -0700
Processing by WelcomesController#index as HTML
Rendered welcomes/index.html.haml within layouts/application (21.7ms)
Completed 500 Internal Server Error in 31ms
** [Airbrake] Notice was not sent due to configuration:
Environment Monitored? false
API key set? false
SystemStackError (stack level too deep):
airbrake (4.0.0) lib/airbrake/rails/middleware.rb:16
Rendered /Users/pierce/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/actionpack-4.1.1/lib/action_dispatch/middleware/templates/rescues/_source.erb (1.5ms)
Rendered /Users/pierce/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/actionpack-4.1.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (4.6ms)
Rendered /Users/pierce/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/actionpack-4.1.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (2.5ms)
Rendered /Users/pierce/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/actionpack-4.1.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (50.5ms)
OK, given that you’ve got nested content, have you tried (it looks like you have, but want to confirm) just deleting the ID (and not commenting it out) to see what happens?
Also, does it make a difference if you set the ID as part of the attributes hash rather than using the hash-sign shortcut?
%section{id: "info"}
%h1 Info
%h2 More info
Does that work? Just trying to figure out what could be the cause.
@geoffharcourt Yes, I get the error if I use the hash-sign shortcut or the full attributes hash: %section#info and %section(id: “info”} both produce an error.
Based on the error I got before I removed airbrake as I am not using it for this project. Now I get a new trace for the stack level too deep error.
Started GET "/welcomes" for 127.0.0.1 at 2014-08-24 23:22:01 -0700
Processing by WelcomesController#index as HTML
Rendered welcomes/index.html.haml within layouts/application (42.7ms)
Completed 500 Internal Server Error in 91ms
SystemStackError (stack level too deep):
actionpack (4.1.1) lib/action_dispatch/middleware/reloader.rb:79
Rendered /Users/pierce/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/actionpack-4.1.1/lib/action_dispatch/middleware/templates/rescues/_source.erb (6.5ms)
Rendered /Users/pierce/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/actionpack-4.1.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (8.3ms)
Rendered /Users/pierce/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/actionpack-4.1.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (17.3ms)
Rendered /Users/pierce/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/actionpack-4.1.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (182.4ms)
I did make a test using an erg template and that does work so I have a workaround. But I really want to track down why this doesn’t work. It doesn’t seem like haml is the problem.
I appreciate any help or direction you can offer in tracking this down.
Can you post your welcome and layout files to a secret Gist and then link to them here? May as well add your WelcomesController
while you’re at it.
Another question: does the error happen regardless of what string you assign as the ID of the tag? Wondering if “info” is somehow to blame…
I have tried a variety of ID values. They all produce the same error.