From 081fa8454913cc443d285b2bd247fbaf79f0e070 Mon Sep 17 00:00:00 2001 From: Aidan Feldman Date: Sun, 5 Apr 2015 03:13:44 -0400 Subject: [PATCH] more cautious checking for NoMethodError hint --- lib/better_errors/raised_exception.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/better_errors/raised_exception.rb b/lib/better_errors/raised_exception.rb index 38528a41..39f11c4f 100644 --- a/lib/better_errors/raised_exception.rb +++ b/lib/better_errors/raised_exception.rb @@ -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)