Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/__better_errors not working #353

Closed
willcosgrove opened this issue Sep 9, 2016 · 4 comments
Closed

/__better_errors not working #353

willcosgrove opened this issue Sep 9, 2016 · 4 comments
Labels
Milestone

Comments

@willcosgrove
Copy link

Ever since rails/rails@266455c the /__better_errors endpoint has been broken.

The changes here and here make it so that instantiating an ActionDispatch::ExceptionWrapper with a nil in place of the exception will result in a 💥

Which is exactly what happens when you go to /__better_errors

when %r{/__better_errors/?\z}
  show_error_page env
def show_error_page(env, exception=nil)
  # ...
  if defined? ActionDispatch::ExceptionWrapper
    status_code = ActionDispatch::ExceptionWrapper.new(env, exception).status_code
  end
  # ...
end

I don't know whether it's the fault of rails for changing the internals of ActionDispatch::ExceptionWrapper, or if exception should have always been non-nil, in which case it's better_error's bug.

What do you think @charliesome? Should I submit a PR here to fix this, or should I take this up with Rails?

@vala
Copy link

vala commented Feb 20, 2017

Since this has not been answered for more than 5 months, I put up a simple snippet to patch my apps thanks to @willcosgrove indications.

You can use it until the issue is answered.

Put the following in an initializer or in a lib file and require it on startup :

module BetterErrors
  class Middleware
    def show_error_page(env, exception=nil)
      type, content = if @error_page
        if text?(env)
          [ 'plain', @error_page.render('text') ]
        else
          [ 'html', @error_page.render ]
        end
      else
        [ 'html', no_errors_page ]
      end

      [500, { "Content-Type" => "text/#{type}; charset=utf-8" }, [content]]
    end
  end
end

@mutantkeyboard
Copy link

Confirmed.
@vala 's code is working and should be included in the patch.

@RobinDaugherty
Copy link
Member

The exception being raised is undefined method 'cause' for nil:NilClass.

@willcosgrove thanks for opening this issue so it could be tracked down. Just want to let you know that if you had mentioned the text of the exception, it would have been much more helpful.

@RobinDaugherty RobinDaugherty added this to the v2.2 milestone Jul 29, 2017
@RobinDaugherty
Copy link
Member

Version 2.2.0 of the gem has been released, so this issue seems to be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants