Skip to content

Commit

Permalink
[refactor] make sure ASN1Error has native cause
Browse files Browse the repository at this point in the history
  • Loading branch information
kares committed Apr 11, 2024
1 parent c197ac8 commit 029a779
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/main/java/org/jruby/ext/openssl/ASN1.java
Original file line number Diff line number Diff line change
Expand Up @@ -1127,12 +1127,11 @@ public static IRubyObject decode(final ThreadContext context,
return decodeImpl(context, (RubyModule) self, obj);
}
catch (IOException e) {
//throw context.runtime.newIOErrorFromException(e);
throw newASN1Error(context.runtime, e.getMessage());
throw newASN1Error(context.runtime, e);
}
catch (IllegalArgumentException e) {
debugStackTrace(context.runtime, e);
throw context.runtime.newArgumentError(e.getMessage());
throw (RaiseException) context.runtime.newArgumentError(e.getMessage()).initCause(e);
}
catch (RuntimeException e) {

Expand Down Expand Up @@ -1212,8 +1211,7 @@ public static IRubyObject decode_all(final ThreadContext context,
arr.append( decodeImpl(context, ASN1, in) );
}
catch (IOException e) {
//throw context.runtime.newIOErrorFromException(e);
throw newASN1Error(context.runtime, e.getMessage());
throw newASN1Error(context.runtime, e);
}
catch (IllegalArgumentException e) {
debugStackTrace(context.runtime, e);
Expand All @@ -1233,6 +1231,10 @@ public static RaiseException newASN1Error(Ruby runtime, String message) {
return Utils.newError(runtime, _ASN1(runtime).getClass("ASN1Error"), message, false);
}

static RaiseException newASN1Error(Ruby runtime, Throwable ex) {
return (RaiseException) newASN1Error(runtime, ex.getMessage()).initCause(ex);
}

static RubyModule _ASN1(final Ruby runtime) {
return (RubyModule) runtime.getModule("OpenSSL").getConstant("ASN1");
}
Expand Down

0 comments on commit 029a779

Please sign in to comment.