Skip to content

Commit

Permalink
[Truffle] Show the path on ENOENT.
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Oct 7, 2016
1 parent 40ae3b6 commit 23dd0d0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
Expand Up @@ -235,31 +235,19 @@ public DynamicObject mathDomainError(String method, Node currentNode) {

@TruffleBoundary
public DynamicObject errnoError(int errno, Node currentNode) {
Errno errnoObj = Errno.valueOf(errno);
if (errnoObj == null) {
return systemCallError(StringUtils.format("Unknown Error (%s)", errno), errno, currentNode);
}

return ExceptionOperations.createSystemCallError(
context.getCoreLibrary().getErrnoClass(errnoObj),
StringOperations.createString(context, StringOperations.encodeRope(errnoObj.description(), UTF8Encoding.INSTANCE)),
context.getCallStack().getBacktrace(currentNode), errno);
return errnoError(errno, "", currentNode);
}

@TruffleBoundary
public DynamicObject errnoError(int errno, String message, Node currentNode) {
public DynamicObject errnoError(int errno, String extraMessage, Node currentNode) {
Errno errnoObj = Errno.valueOf(errno);
if (errnoObj == null) {
return systemCallError(StringUtils.format("Unknown Error (%s) - %s", errno, message), errno, currentNode);
}

DynamicObject errnoClass = context.getCoreLibrary().getErrnoClass(errnoObj);
if(errnoClass == null){
errnoClass = context.getCoreLibrary().getSystemCallErrorClass();
message = "Unknown error: " + errno;
if (errnoObj == null || errnoClass == null) {
return systemCallError(StringUtils.format("Unknown Error (%s)%s", errno, extraMessage), errno, currentNode);
}

final DynamicObject errorMessage = StringOperations.createString(context, StringOperations.encodeRope(StringUtils.format("%s%s", errnoObj.description(), message), UTF8Encoding.INSTANCE));
String fullMessage = StringUtils.format("%s%s", errnoObj.description(), extraMessage);
DynamicObject errorMessage = StringOperations.createString(context, StringOperations.encodeRope(fullMessage, UTF8Encoding.INSTANCE));

return ExceptionOperations.createSystemCallError(
errnoClass,
Expand Down
Expand Up @@ -94,17 +94,21 @@ public IOPrimitiveArrayArgumentsNode(RubyContext context, SourceSection sourceSe
super(context, sourceSection);
}

protected int ensureSuccessful(int result, int errno) {
protected int ensureSuccessful(int result, int errno, String extra) {
assert result >= -1;
if (result == -1) {
errorProfile.enter();
throw new RaiseException(coreExceptions().errnoError(errno, this));
throw new RaiseException(coreExceptions().errnoError(errno, extra, this));
}
return result;
}

protected int ensureSuccessful(int result) {
return ensureSuccessful(result, posix().errno());
return ensureSuccessful(result, posix().errno(), "");
}

protected int ensureSuccessful(int result, String extra) {
return ensureSuccessful(result, posix().errno(), " - " + extra);
}
}

Expand Down Expand Up @@ -183,13 +187,18 @@ private int getWRONLY() {

}

@Primitive(name = "io_open", needsSelf = false, lowerFixnum = { 2, 3 }, unsafe = UnsafeGroup.IO)
@Primitive(name = "io_open", needsSelf = false, lowerFixnum = {2, 3}, unsafe = UnsafeGroup.IO)
public static abstract class IOOpenPrimitiveNode extends IOPrimitiveArrayArgumentsNode {

@TruffleBoundary(throwsControlFlowException = true)
@Specialization(guards = "isRubyString(path)")
public int open(DynamicObject path, int mode, int permission) {
return ensureSuccessful(posix().open(StringOperations.getString(path), mode, permission));
String pathString = StringOperations.getString(path);
int fd = posix().open(pathString, mode, permission);
if (fd == -1) {
ensureSuccessful(fd, pathString);
}
return fd;
}

}
Expand Down Expand Up @@ -377,7 +386,7 @@ public void performReopenPath(DynamicObject self, DynamicObject path, int mode)
if (fdTarget > 0) {
ensureSuccessful(posix().close(fdTarget));
}
ensureSuccessful(result, errno); // throws
ensureSuccessful(result, errno, targetPathString); // throws
return;
}
} else {
Expand Down

0 comments on commit 23dd0d0

Please sign in to comment.