Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fixes issues with handling incorrect number of command arguments with JRuby #204

Merged
merged 1 commit into from

2 participants

@hectcastro

It looks like Thor decides how command argument errors are handled based on exception backtraces. After taking a closer look, JRuby backtraces include references to Java source code that disrupt handle_argument_error?. In order to address this, I added an additional filter to the backtrace that rejects Java source files if RUBY_PLATFORM matches /java/.

This patch is meant to resolve #179 and makes the specs below pass with JRuby. Any alternate solutions or feedback are welcome.

rspec ./spec/group_spec.rb:34 # Thor::Group#start raises an error when a Thor group task expects arguments
rspec ./spec/group_spec.rb:128 # Thor::Group#invoke_from_option with default type allows to invoke a class from the class binding by the given option
rspec ./spec/runner_spec.rb:107 # Thor::Runner#start does not swallow Thor::Group InvocationError
rspec ./spec/runner_spec.rb:112 # Thor::Runner#start does not swallow Thor InvocationError
rspec ./spec/thor_spec.rb:174 # Thor#start raises an error if a required param is not provided
rspec ./spec/thor_spec.rb:204 # Thor Thor#start when the user enters an unambiguous substring of a command should invoke a command, even when there's an alias the resolves to the same command
@wycats
Owner

I am willing to accept this, and half-wrote this fix myself, but I am extremely unhappy with the heuristic being used here. We should strip this down and try to rethink what we're doing here in the first place.

@wycats wycats merged commit b2be097 into erikhuda:master
@wycats
Owner

I should note that this doesn't fix similar issues with Rubinius, and it's harder to fix Rubinius.

@hectcastro

I definitely can't disagree.

@pmenglund pmenglund referenced this pull request from a commit in pmenglund/thor
@nerdyc nerdyc Use #public_methods to check whether a command method is public, rath…
…er than private_methods+protected_methods.

(Works around bug #204 in MacRuby)
677b1e0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 1 deletion.
  1. +1 −1  lib/thor/task.rb
View
2  lib/thor/task.rb
@@ -87,7 +87,7 @@ def local_method?(instance, name)
end
def sans_backtrace(backtrace, caller) #:nodoc:
- saned = backtrace.reject { |frame| frame =~ FILE_REGEXP }
+ saned = backtrace.reject { |frame| frame =~ FILE_REGEXP || (frame =~ /\.java:/ && RUBY_PLATFORM =~ /java/) }
saned -= caller
end
Something went wrong with that request. Please try again.