Skip to content

Commit

Permalink
[fix] convert IOException to Ruby exception correctly
Browse files Browse the repository at this point in the history
follow up on: a011807 (#242)
  • Loading branch information
kares committed May 22, 2024
1 parent c201ae3 commit d97d868
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/jruby/ext/openssl/SSLSocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ private IRubyObject sysreadImpl(final ThreadContext context,
}
catch (IOException ex) {
debugStackTrace(runtime, "SSLSocket.sysreadImpl", ex);
throw Utils.newError(runtime, runtime.getIOError(), ex);
throw Utils.newError(runtime::newIOErrorFromException, ex);
}
}

Expand Down Expand Up @@ -952,7 +952,7 @@ private IRubyObject syswriteImpl(final ThreadContext context,
}
catch (IOException ex) {
debugStackTrace(runtime, "SSLSocket.syswriteImpl", ex);
throw runtime.newIOErrorFromException(ex);
throw Utils.newError(runtime::newIOErrorFromException, ex);
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/jruby/ext/openssl/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.HashSet;
import java.util.function.Function;

import org.jruby.*;
import org.jruby.exceptions.RaiseException;
Expand Down Expand Up @@ -94,6 +95,12 @@ static RaiseException newError(Ruby runtime, RubyClass errorClass, String msg, T
return ex;
}

static <T extends Throwable> RaiseException newError(Function<T, RaiseException> errorFunction, T e) {
RaiseException ex = errorFunction.apply(e);
ex.initCause(e);
return ex;
}

// reinvented parts of org.jruby.runtime.Helpers for compatibility with "older" JRuby :

static IRubyObject invoke(ThreadContext context, IRubyObject self, String name, Block block) {
Expand Down

0 comments on commit d97d868

Please sign in to comment.