Skip to content

Commit

Permalink
Merge pull request #8223 from enebo/exception_messages
Browse files Browse the repository at this point in the history
Make Exception#detailed_message,full_message pass specs
  • Loading branch information
enebo committed May 3, 2024
2 parents ffecfda + 4de1ec0 commit cf4f0d4
Show file tree
Hide file tree
Showing 3 changed files with 187 additions and 107 deletions.
31 changes: 28 additions & 3 deletions core/src/main/java/org/jruby/RubyException.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,29 @@ public IRubyObject full_message(ThreadContext context) {

@JRubyMethod
public IRubyObject full_message(ThreadContext context, IRubyObject opts) {
return RubyString.newString(context.runtime, TraceType.printFullMessage(context, this, opts));
return TraceType.printFullMessage(context, this, opts);
}

@JRubyMethod
public IRubyObject detailed_message(ThreadContext context) {
return detailed_message(context, (IRubyObject) null);
}

@JRubyMethod
public IRubyObject detailed_message(ThreadContext context, IRubyObject opts) {
return TraceType.printDetailedMessage(context, this, opts);
}

@JRubyMethod(optional = 1)
public IRubyObject detailed_message(ThreadContext context, IRubyObject[] args) {
switch (args.length) {
case 0:
return detailed_message(context);
case 1:
return detailed_message(context, args[0]);
default:
throw context.runtime.newArgumentError(args.length, 0, 1);
}
}

@JRubyMethod(visibility = PRIVATE)
Expand Down Expand Up @@ -473,8 +495,11 @@ public void printBacktrace(PrintStream errorStream) {
* @param errorStream the PrintStream to which backtrace should be printed
*/
public void printBacktrace(PrintStream errorStream, int skip) {
IRubyObject trace = callMethod(getRuntime().getCurrentContext(), "backtrace");
TraceType.printBacktraceToStream(trace, errorStream, skip);
ThreadContext context = getRuntime().getCurrentContext();
IRubyObject trace = callMethod(context, "backtrace");
RubyString string = RubyString.newEmptyString(getRuntime());
TraceType.printBacktraceToStream(context, trace, string, skip);
errorStream.print(string);
}

private boolean isArrayOfStrings(IRubyObject backtrace) {
Expand Down

0 comments on commit cf4f0d4

Please sign in to comment.