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

Before block is run twice when an error occurs #818

Closed
Wardrop opened this Issue Mar 30, 2012 · 3 comments

Comments

Projects
None yet
3 participants
@Wardrop

Wardrop commented Mar 30, 2012

When an exception occurs, the before blocks are run a second time before the error block is called. It's like the full request cycle is being invoked when an error occurs. This only seems to apply to exceptions. Calls to halt do not cause the error blocks to be re-run.

Is this the intended behavior, and if so, in what scenario is this behavior desirable?

Edit: I should add that I'm using 0.10.5 as I've got another issue open regarding a problem encountered while upgrading to 0.10.6.

@dariocravero

This comment has been minimized.

Show comment
Hide comment
@dariocravero

dariocravero Jan 10, 2013

Contributor

Yes, you're right, it does happen like that and still happens in both 0.10.7 and edge. Same thing happens on Sinatra.

Test code:

  error 500 do
    'error 500'
  end

  before do
    puts 'before'                                                                                                                                                                    
  end

  get :index do
    raise Exception, "Oops"
  end

or jist it with curl -L http://jister.uxtemple.com |which bash-s 57c7415df6c0bbbd0e0d ;)

Will dig deeper and see what happens. Have a feeling it might be connected to #931.

Contributor

dariocravero commented Jan 10, 2013

Yes, you're right, it does happen like that and still happens in both 0.10.7 and edge. Same thing happens on Sinatra.

Test code:

  error 500 do
    'error 500'
  end

  before do
    puts 'before'                                                                                                                                                                    
  end

  get :index do
    raise Exception, "Oops"
  end

or jist it with curl -L http://jister.uxtemple.com |which bash-s 57c7415df6c0bbbd0e0d ;)

Will dig deeper and see what happens. Have a feeling it might be connected to #931.

@ujifgc

This comment has been minimized.

Show comment
Hide comment
@ujifgc

ujifgc Jan 10, 2013

Member

The issue is related to #591

    def dispatch!
      static! if settings.static? && (request.get? || request.head?)
      route!
    rescue ::Exception => boom
      filter! :before #here is the second call for filters
      handle_exception!(boom)
    ensure
      filter! :after unless env['sinatra.static_file']
    end
Member

ujifgc commented Jan 10, 2013

The issue is related to #591

    def dispatch!
      static! if settings.static? && (request.get? || request.head?)
      route!
    rescue ::Exception => boom
      filter! :before #here is the second call for filters
      handle_exception!(boom)
    ensure
      filter! :after unless env['sinatra.static_file']
    end

ujifgc added a commit to ujifgc/padrino-framework that referenced this issue Jan 10, 2013

nesquena added a commit that referenced this issue Jan 10, 2013

@dariocravero

This comment has been minimized.

Show comment
Hide comment
@dariocravero

dariocravero Jan 10, 2013

Contributor

Confirmed it fixes it. Thanks @ujifgc!!

Contributor

dariocravero commented Jan 10, 2013

Confirmed it fixes it. Thanks @ujifgc!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment