Skip to content

Commit

Permalink
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -9,12 +9,9 @@
*/
package org.jruby.truffle.nodes.rubinius;

import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;
import jnr.constants.platform.Errno;
import org.jruby.truffle.nodes.RubyGuards;
import org.jruby.truffle.runtime.RubyContext;

/**
@@ -31,7 +28,7 @@ public ExceptionErrnoErrorPrimitiveNode(RubyContext context, SourceSection sourc

@Specialization
public DynamicObject exceptionErrnoError(DynamicObject message, int errno) {
return getContext().getCoreLibrary().errnoError(errno, this);
return getContext().getCoreLibrary().errnoError(errno, message.toString(), this);
}

}
Original file line number Diff line number Diff line change
@@ -906,6 +906,18 @@ public DynamicObject errnoError(int errno, Node currentNode) {
return ExceptionNodes.createRubyException(getErrnoClass(errnoObj), Layouts.STRING.createString(Layouts.CLASS.getInstanceFactory(stringClass), RubyString.encodeBytelist(errnoObj.description(), UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null), RubyCallStack.getBacktrace(currentNode));
}

public DynamicObject errnoError(int errno, String message, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();

Errno errnoObj = Errno.valueOf(errno);
if (errnoObj == null) {
return systemCallError(String.format("Unknown Error (%s) - %s", errno, message), currentNode);
}

final DynamicObject errorMessage = Layouts.STRING.createString(Layouts.CLASS.getInstanceFactory(stringClass), RubyString.encodeBytelist(String.format("%s - %s", errnoObj.description(), message), UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null);
return ExceptionNodes.createRubyException(getErrnoClass(errnoObj), errorMessage, RubyCallStack.getBacktrace(currentNode));
}

public DynamicObject indexError(String message, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
return ExceptionNodes.createRubyException(indexErrorClass, Layouts.STRING.createString(Layouts.CLASS.getInstanceFactory(stringClass), RubyString.encodeBytelist(message, UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null), RubyCallStack.getBacktrace(currentNode));

2 comments on commit 893d10b

@eregon
Copy link
Member

@eregon eregon commented on 893d10b Sep 15, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!
Maybe differentiate if message is nil, since then having - nil in the error message does not seem so useful.

Sorry, something went wrong.

@nirvdrum
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought of that and for some reason didn't come up with the simple solution of using a guard. I'll fix up shortly.

Sorry, something went wrong.

Please sign in to comment.