-
-
Notifications
You must be signed in to change notification settings - Fork 925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"LoadError: no such file to load" if IOException is raised in loaded file #4194
Comments
https://github.com/jruby/jruby/blob/master/core/src/main/java/org/jruby/runtime/load/LibrarySearcher.java#L246 is the bit that raises the faulty exception, trying to find a fix. |
I noticed the other day that MRI does not appear to wrap raised exceptions in LoadError anymore, while we still do. I am not certain when it DOES throw LoadError, but I suspect it's only for actual load/require problems. |
This just bit me. Before finding this issue I managed to produce a minimized reproduction, in case it helps, shown below. @headius : some further notes on this.
% jruby -v
jruby 9.1.7.0 (2.3.1) 2017-01-11 68056ae OpenJDK 64-Bit Server VM 25.121-b13 on 1.8.0_121-b13 +jit [linux-x86_64]
% cat ./raises.rb
require 'java'
class CLI
def run
raise Java::java.io.IOException.new( "me" )
end
end
CLI.new.run
% cat ./loads.rb
load File.expand_path( "../raises.rb", __FILE__ )
% jruby ./raises.rb
Unhandled Java exception: java.io.IOException: me
java.io.IOException: me
newInstance0 at sun/reflect/NativeConstructorAccessorImpl.java:-2
newInstance at sun/reflect/NativeConstructorAccessorImpl.java:62
newInstance at sun/reflect/DelegatingConstructorAccessorImpl.java:45
newInstance at java/lang/reflect/Constructor.java:423
newInstanceDirect at org/jruby/javasupport/JavaConstructor.java:278
call at org/jruby/java/invokers/ConstructorInvoker.java:85
call at org/jruby/java/invokers/ConstructorInvoker.java:174
cacheAndCall at org/jruby/runtime/callsite/CachingCallSite.java:348
callBlock at org/jruby/runtime/callsite/CachingCallSite.java:173
call at org/jruby/runtime/callsite/CachingCallSite.java:177
call at org/jruby/java/proxies/ConcreteJavaProxy.java:56
cacheAndCall at org/jruby/runtime/callsite/CachingCallSite.java:348
callBlock at org/jruby/runtime/callsite/CachingCallSite.java:173
call at org/jruby/runtime/callsite/CachingCallSite.java:177
newInstance at org/jruby/RubyClass.java:1001
call at org/jruby/RubyClass$INVOKER$i$newInstance.gen:-1
call at org/jruby/internal/runtime/methods/DynamicMethod.java:200
call at org/jruby/java/proxies/ConcreteJavaProxy.java:158
cacheAndCall at org/jruby/runtime/callsite/CachingCallSite.java:338
call at org/jruby/runtime/callsite/CachingCallSite.java:163
invokeOther6:new at $_dot_/./raises.rb:5
run at ./raises.rb:5
call at org/jruby/internal/runtime/methods/CompiledIRMethod.java:155
cacheAndCall at org/jruby/runtime/callsite/CachingCallSite.java:318
call at org/jruby/runtime/callsite/CachingCallSite.java:131
invokeOther10:run at $_dot_/./raises.rb:9
<main> at ./raises.rb:9
invokeWithArguments at java/lang/invoke/MethodHandle.java:627
load at org/jruby/ir/Compiler.java:90
runScript at org/jruby/Ruby.java:823
runNormally at org/jruby/Ruby.java:742
runNormally at org/jruby/Ruby.java:760
runFromMain at org/jruby/Ruby.java:573
doRunFromMain at org/jruby/Main.java:417
internalRun at org/jruby/Main.java:305
run at org/jruby/Main.java:232
main at org/jruby/Main.java:204
% jruby ./loads.rb
LoadError: no such file to load -- /home/david/src/test/jruby_load_e_oddness/raises
load at org/jruby/RubyKernel.java:979
<main> at ./loads.rb:1
% jruby17 -v ./loads.rb
jruby 1.7.26 (1.9.3p551) 2016-08-26 69763b8 on OpenJDK 64-Bit Server VM 1.8.0_121-b13 +jit [linux-amd64]
LoadError: load error: /home/david/src/test/jruby_load_e_oddness/raises.rb -- java.io.IOException: me
load at org/jruby/RubyKernel.java:1059
(root) at ./loads.rb:1 |
Still an issue. We have discussed allowing Java exceptions to percolate out, but this is simply a tricky case to solve. We want to handle IOException that happens during the process of actually loading the file contents, but it's hard to differentiate that from IOException raised by the script in question. Will look at it quickly. |
This allows us to propagate IOException rather than wrongly interpreting it as an error caused by the load of the file itself. It still gets wrapped in a LoadError, but at least it does not provide a misleading message. Relates to jruby#4194.
I have a fix for the bad error message, but we do still wrap the IOException in a LoadError, which may not be correct. At least now it prints out the actual exception raised. See #6313. |
Environment
jruby 9.1.5.0 (2.3.1) 2016-09-07 036ce39 Java HotSpot(TM) 64-Bit Server VM 25.92-b14 on 1.8.0_92-b14 +jit [darwin-x86_64]
Darwin xxxxx.local 15.6.0 Darwin Kernel Version 15.6.0: Mon Aug 29 20:21:34 PDT 2016; root:xnu-3248.60.11~1/RELEASE_X86_64 x86_64
But we originally had the issue on Linux too (same JRuby version).
Expected Behavior
To see
Java::JavaIo::IOException
and the stacktraceActual Behavior
LoadError: no such file to load -- test.rb
Reproduction
https://gist.github.com/olleolleolle/c56a31f32401d944c87d6c37a82c0f14
The text was updated successfully, but these errors were encountered: