500 page instead of stack trace on any exception

Hi,

maybe this has come up before, but a search turned up nothing useful...

Lately I'm getting the 500 error page whenever something goes wrong,
for any kind of error,
instead of the standard error page with explanation, stack trace, line
number etc.

I'm not aware of changing anything in the configuration.
I'd be really grateful for any tips on how to get my detailed error
pages back for debugging.

Thanks in advance,
Elmar

My configuration: Suse Linux , ruby 1.8.5, rails 1.1.6, server on
localhost:8080 started from within radrails 0.7.1

Are you running in production mode? Only development gives the debugging
info.
Also, you'll get the server error if there are serious problems like
your app can't even start up. Problems I've had that have caused this:

1) Incorrect location of ruby on the #! shebang line on the first line
of dispatch.fcgi
2) Logfiles unable to be written(though I think this will usually crash
the whole web server process)
3) I'm sure there were other things, but I can't remember them. Look at
the DB connection, dispatch.rb
   and anything else that may happen before the app can even start.

Elmar Schraml wrote:

I am running in development mode, and have
config.action_controller.consider_all_requests_local = true
in config/environments/development.rb

The app and server are starting and running fine in general,
it's just that any exception (typing errors, compile errors, whatever)
leads to the generic 500 page being shown rather than the page with the
stack trace.

This started happening around the first time that I started using the
app from other computers than the one where it is hosted, so it might
have something to do with the server confusing local (from localhost)
and non-local requests

Elmar Schraml wrote:

Hi,

maybe this has come up before, but a search turned up nothing useful...

Lately I'm getting the 500 error page whenever something goes wrong,
for any kind of error,
instead of the standard error page with explanation, stack trace, line
number etc.

I'm not aware of changing anything in the configuration.
I'd be really grateful for any tips on how to get my detailed error
pages back for debugging.

Thanks in advance,
Elmar

My configuration: Suse Linux , ruby 1.8.5, rails 1.1.6, server on
localhost:8080 started from within radrails 0.7.1

I was having the same problem and with a little debugging I determined
it was due to my config.action_view.erb_trim_mode setting in
config/environment.rb.

After a little research, I discovered the following:

If the ERB::Compiler::TrimScanner#explicit_trim_line is not invoked,
Rails (1.1.6|EDGE) rescue template craps out and doesn't show the
stack trace. Instead, the public/500.html page is displayed. I believe
this is because the omittance of the newline will place serveral lines
of Ruby code on a single line and cause compiler/parse errors.

If using '<' or '<>', you will have to strategically place
newlines in your templates. Otherwise, you must invoke the
explicit_trim_line method, which is enabled by including a hyphen in
config.action_view.erb_trim_mode.
All possible values for erb_trim_mode:

   1. 1
   2. 2
   3. 0
   4. nil
   5. '%'
   6. '%-'
   7. '%>'
   8. '%<>'
   9. '-' (Rails default)
  10. '>'
  11. '<>'

The source for ERB can be found in ruby-1.8.4/lib/erb.rb.

I've included an interesting method:

def prepare_trim_mode(mode)
  case mode
  when 1
    return [false, '>']
  when 2
    return [false, '&lt;>']
  when 0
    return [false, nil]
  when String
    perc = mode.include?('%')
    if mode.include?('-')
      return [perc, '-']
    elsif mode.include?('&lt;>')
      return [perc, '&lt;>']
    elsif mode.include?('>')
      return [perc, '>']
    else
      [perc, nil]
    end
else
  return [false, nil]
end
end

Other interesting methods include:
   1. explicit_trim_line (invoked by specifying a hyphen)
   2. trim_line1 (invoked by specifying '%>' or '>' or 1)
   3. trim_line2 (invoked by specifying '%<>' or '<>' or 2)
   4. TrimScanner#initialize

-pachl

Fixed it by simply removing
ActionView::Base.erb_trim_mode = '>'
from config/environment.rb

I originally put that in following the advice on
http://railsexpress.de/blog/articles/2005/12/06/trim-your-output,
but there's not really a good reason to mess with this option.

Thanks a lot to pachl for pointing out the cause of the bug.