Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Merged
merged 1 commit into from

2 participants

Alex Tambellini Charles Oliver Nutter
Alex Tambellini
Collaborator

No description provided.

Charles Oliver Nutter headius merged commit 48dd511 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
2  spec/tags/1.8/ruby/core/kernel/abort_tags.txt
View
@@ -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 spec/tags/1.9/ruby/core/kernel/abort_tags.txt
View
@@ -1,4 +0,0 @@
-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
6 src/org/jruby/Ruby.java
View
@@ -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) {
19 src/org/jruby/RubyKernel.java
View
@@ -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
}
@@ -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];
@@ -837,6 +840,12 @@ 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);
@@ -844,7 +853,11 @@ private static void exit(Ruby runtime, IRubyObject[] args, boolean hard) {
throw new MainExitException(status, true);
}
} else {
- throw runtime.newSystemExit(status);
+ if (message == null) {
+ throw runtime.newSystemExit(status);
+ } else {
+ throw runtime.newSystemExit(status, message);
+ }
}
}
4 src/org/jruby/RubySystemExit.java
View
@@ -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);
}
5 src/org/jruby/RubyThread.java
View
@@ -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;
Something went wrong with that request. Please try again.