diff --git a/core/src/main/java/org/jruby/runtime/Helpers.java b/core/src/main/java/org/jruby/runtime/Helpers.java index 935a505d200..221f01da983 100644 --- a/core/src/main/java/org/jruby/runtime/Helpers.java +++ b/core/src/main/java/org/jruby/runtime/Helpers.java @@ -10,6 +10,7 @@ import java.net.BindException; import java.net.PortUnreachableException; +import java.net.SocketException; import java.nio.channels.ClosedChannelException; import java.nio.channels.NonReadableChannelException; import java.nio.channels.NonWritableChannelException; @@ -257,7 +258,7 @@ public static Errno errnoFromException(Throwable t) { // Try specific exception types by rethrowing and catching. try { throw t; - } catch (FileNotFoundException fnfe) { + } catch (FileNotFoundException | NoSuchFileException fnfe) { return Errno.ENOENT; } catch (EOFException eofe) { return Errno.EPIPE; @@ -271,15 +272,11 @@ public static Errno errnoFromException(Throwable t) { return Errno.EEXIST; } catch (FileSystemLoopException fsle) { return Errno.ELOOP; - } catch (NoSuchFileException nsfe) { - return Errno.ENOENT; } catch (NotDirectoryException nde) { return Errno.ENOTDIR; } catch (AccessDeniedException ade) { return Errno.EACCES; - } catch (DirectoryNotEmptyException dnee) { - return errnoFromMessage(dnee); - } catch (BindException be) { + } catch (IOException be) { return errnoFromMessage(be); } catch (NotYetConnectedException nyce) { return Errno.ENOTCONN; @@ -288,12 +285,6 @@ public static Errno errnoFromException(Throwable t) { return Errno.EINVAL; } catch (IllegalArgumentException nrce) { return Errno.EINVAL; - } catch (IOException ioe) { - String message = ioe.getMessage(); - // Raised on Windows for process launch with missing file - if (message.endsWith("The system cannot find the file specified")) { - return Errno.ENOENT; - } } catch (Throwable t2) { // fall through } @@ -319,6 +310,7 @@ private static Errno errnoFromMessage(Throwable t) { return Errno.ECONNABORTED; case "Broken pipe": return Errno.EPIPE; + case "Connection reset": case "Connection reset by peer": case "An existing connection was forcibly closed by the remote host": return Errno.ECONNRESET; @@ -352,7 +344,13 @@ private static Errno errnoFromMessage(Throwable t) { case "Protocol family not supported": return Errno.EPFNOSUPPORT; } + + // Raised on Windows for process launch with missing file + if (errorMessage.endsWith("The system cannot find the file specified")) { + return Errno.ENOENT; + } } + return null; }