Skip to content
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

Closed
olleolleolle opened this issue Sep 30, 2016 · 5 comments · Fixed by #6313
Closed

"LoadError: no such file to load" if IOException is raised in loaded file #4194

olleolleolle opened this issue Sep 30, 2016 · 5 comments · Fixed by #6313
Milestone

Comments

@olleolleolle
Copy link
Member

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 stacktrace

Actual Behavior

LoadError: no such file to load -- test.rb

Reproduction

https://gist.github.com/olleolleolle/c56a31f32401d944c87d6c37a82c0f14

@auroranockert
Copy link

auroranockert commented Sep 30, 2016

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.

@headius
Copy link
Member

headius commented Sep 30, 2016

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.

@dekellum
Copy link
Contributor

dekellum commented Mar 3, 2017

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.

  • As best I can tell, this only happens with IOException and derivatives, not other java exception classes or ruby exceptions.
  • You suggest the LoadError is wrapping the IOException, but wouldn't jruby's normal exception dumping show the wrapped exception in this case? On jruby 9.1.7 it doesn't.
  • On jruby 1.7.26 (bottom) it does at least show the message (but not the stack) of the IOException which I guess is why this never bothered me before on 1.7.x
  • This load scenario would effect almost any CLI utility written in jruby that uses java.io and is installed as gem and executed via the normal gem wrappers.
  • Workarounds would include wrapping these exceptions in something else, or to catch and handle the exceptions via the loaded ruby file.
% 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

@headius
Copy link
Member

headius commented Jul 9, 2020

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.

headius added a commit to headius/jruby that referenced this issue Jul 9, 2020
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.
@headius headius linked a pull request Jul 9, 2020 that will close this issue
@headius
Copy link
Member

headius commented Jul 9, 2020

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.

@headius headius added this to the JRuby 9.3.0.0 milestone Jul 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants