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

Make Exception#detailed_message,full_message pass specs #8223

Merged
merged 3 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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