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

Kernel.abort should set the exception message to the given message #703

Merged
merged 1 commit into from
May 4, 2013
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions spec/tags/1.8/ruby/core/kernel/abort_tags.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
fails:Kernel#abort sets the exception message to the given message
fails:Kernel#abort coerces the argument with #to_str
fails:Kernel.abort sets the exception message to the given message
fails:Kernel.abort coerces the argument with #to_str
4 changes: 0 additions & 4 deletions spec/tags/1.9/ruby/core/kernel/abort_tags.txt

This file was deleted.

6 changes: 5 additions & 1 deletion src/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
Expand Up @@ -3589,7 +3589,11 @@ public RaiseException newSystemStackError(String message, StackOverflowError soe
}

public RaiseException newSystemExit(int status) {
return new RaiseException(RubySystemExit.newInstance(this, status));
return new RaiseException(RubySystemExit.newInstance(this, status, "exit"));
}

public RaiseException newSystemExit(int status, String message) {
return new RaiseException(RubySystemExit.newInstance(this, status, message));
}

public RaiseException newIOError(String message) {
Expand Down
19 changes: 16 additions & 3 deletions src/org/jruby/RubyKernel.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,13 @@ public static IRubyObject gets(ThreadContext context, IRubyObject recv, IRubyObj
public static IRubyObject abort(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
Ruby runtime = context.runtime;

RubyString message = null;
if(args.length == 1) {
runtime.getGlobalVariables().get("$stderr").callMethod(context,"puts",args[0].convertToString());
message = args[0].convertToString();
runtime.getGlobalVariables().get("$stderr").callMethod(context, "puts", message);
}

exit(runtime, new IRubyObject[] { runtime.getFalse() }, false);
exit(runtime, new IRubyObject[] { runtime.getFalse(), message }, false);
return runtime.getNil(); // not reached
}

Expand Down Expand Up @@ -827,6 +829,7 @@ public static IRubyObject exit_bang(IRubyObject recv, IRubyObject[] args) {

private static void exit(Ruby runtime, IRubyObject[] args, boolean hard) {
int status = hard ? 1 : 0;
String message = null;

if (args.length > 0) {
RubyObject argument = (RubyObject) args[0];
Expand All @@ -837,14 +840,24 @@ private static void exit(Ruby runtime, IRubyObject[] args, boolean hard) {
}
}

if (args.length == 2) {
if (args[1] instanceof RubyString) {
message = ((RubyString) args[1]).toString();
}
}

if (hard) {
if (runtime.getInstanceConfig().isHardExit()) {
System.exit(status);
} else {
throw new MainExitException(status, true);
}
} else {
throw runtime.newSystemExit(status);
if (message == null) {
throw runtime.newSystemExit(status);
} else {
throw runtime.newSystemExit(status, message);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/org/jruby/RubySystemExit.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public static RubyClass createSystemExitClass(Ruby runtime, RubyClass exceptionC
return systemExitClass;
}

public static RubySystemExit newInstance(Ruby runtime, int status) {
public static RubySystemExit newInstance(Ruby runtime, int status, String message) {
RubyClass exc = runtime.getSystemExit();
IRubyObject[] exArgs = new IRubyObject[] {
runtime.newFixnum(status),
runtime.newString("exit") };
runtime.newString(message) };
return (RubySystemExit) exc.newInstance(runtime.getCurrentContext(), exArgs, Block.NULL_BLOCK);
}

Expand Down
5 changes: 2 additions & 3 deletions src/org/jruby/RubyThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -1099,9 +1099,8 @@ public void exceptionRaised(RaiseException exception) {

if (!runtime.is1_9()) {
runtime.printError(rubyException);

systemExit = RubySystemExit.newInstance(runtime, 1);
systemExit.message = rubyException.message;
String message = rubyException.message.convertToString().toString();
systemExit = RubySystemExit.newInstance(runtime, 1, message);
systemExit.set_backtrace(rubyException.backtrace());
} else {
systemExit = rubyException;
Expand Down