Skip to content

Commit

Permalink
Revert to previous backtrace sanitizing behavior.
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Feb 3, 2010
1 parent ba20598 commit ef676f5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions lib/thor/task.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Thor
class Task < Struct.new(:name, :description, :usage, :options)
FILE_REGEXP = /^#{Regexp.escape(File.expand_path(__FILE__))}:[\w:]+ `run'$/
FILE_REGEXP = /^#{Regexp.escape(File.dirname(__FILE__))}/

# A dynamic task that handles method missing scenarios.
class Dynamic < Task
Expand Down Expand Up @@ -78,15 +78,15 @@ def public_method?(instance) #:nodoc:
(collection & [name.to_s, name.to_sym]).empty?
end

# For Ruby <= 1.8.7, we have to match the method name that we are trying to call.
# In Ruby >= 1.9.1, we have to match the method run in this file.
def backtrace_match?(backtrace) #:nodoc:
method_name = /`#{Regexp.escape(name.split(':').last)}'/
backtrace =~ method_name || backtrace =~ FILE_REGEXP
def sans_backtrace(backtrace, caller) #:nodoc:
saned = backtrace.reject { |frame| frame =~ FILE_REGEXP }
saned -= caller
end

def parse_argument_error(instance, e, caller) #:nodoc:
if e.message =~ /wrong number of arguments/ && backtrace_match?(e.backtrace.first.to_s)
backtrace = sans_backtrace(e.backtrace, caller)

if backtrace.empty? && e.message =~ /wrong number of arguments/
if instance.is_a?(Thor::Group)
raise e, "'#{name}' was called incorrectly. Are you sure it has arity equals to 0?"
else
Expand Down
2 changes: 1 addition & 1 deletion spec/thor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
end

it "raises when an exception happens within the task call" do
lambda { MyScript.start(["call_myself_with_wrong_arity", "--debug"]) }.must raise_error
lambda { MyScript.start(["call_myself_with_wrong_arity"]) }.must raise_error(ArgumentError)
end
end

Expand Down

0 comments on commit ef676f5

Please sign in to comment.