Skip to content

Commit

Permalink
more cautious checking for NoMethodError hint
Browse files Browse the repository at this point in the history
  • Loading branch information
afeld committed Apr 5, 2015
1 parent 56340ab commit 081fa84
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/better_errors/raised_exception.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,16 @@ def setup_hint
case exception
when NoMethodError
matches = /\Aundefined method `([^']+)' for ([^:]+):(\w+)\z/.match(message)
method = matches[1]
val = matches[2]
klass = matches[3]
if matches
method = matches[1]
val = matches[2]
klass = matches[3]

if val == "nil"
@hint = "Something is `nil` when it probably shouldn't be."
else
@hint = "`#{method}` is being called on a `#{klass}`, which probably isn't the type you were expecting."
if val == "nil"
@hint = "Something is `nil` when it probably shouldn't be."
else
@hint = "`#{method}` is being called on a `#{klass}`, which probably isn't the type you were expecting."
end
end
when NameError
matches = /\Aundefined local variable or method `([^']+)' for/.match(message)
Expand Down

0 comments on commit 081fa84

Please sign in to comment.