sinatra / sinatra/sinatra

Catchall error block fails to catch direct decendants of Exception

Open
#1,548 17 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

waiting for feedback
Dominant language
Ruby
Stars
12.5k
Forks
2.1k
PR merge metrics
No merged PRs in 30d

Description

Because the conditional on this line checks for strictly less than instead of less than or equal to, error blocks are unable to catch any thing which is a direct descendant of Exception.

https://github.com/sinatra/sinatra/blob/eee711bce740d38a9a91aa6028688c9a6d74b23b/lib/sinatra/base.rb#L1153

Here's a quick (untested) example:

require 'sinatra'

error do
  puts "Error block called!"
end

get "/" do
  raise StandardError
end

After visiting /, the error block will not be called. If this is by design, then this seems like a strange design decision. If it isn't, then I'd be happy to open a PR for this.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Inspect the conditional in lib/sinatra/base.rb around line 1153, then reproduce the issue with the error block and GET / example from the report. Confirm that a direct descendant of Exception reaches the catchall handler and add regression coverage; done means the error block is called for that request.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
backend
Issue type
Bug
Difficulty
1/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.