@@ -25,11 +25,16 @@ public abstract class ExceptionPrimitiveNodes {
25
25
@ RubiniusPrimitive (name = "exception_errno_error" , needsSelf = false )
26
26
public static abstract class ExceptionErrnoErrorPrimitiveNode extends RubiniusPrimitiveNode {
27
27
28
- protected final int ENOENT = Errno .ENOENT .intValue ();
29
- protected final int EBADF = Errno .EBADF .intValue ();
30
- protected final int EEXIST = Errno .EEXIST .intValue ();
31
- protected final int EACCES = Errno .EACCES .intValue ();
32
- protected final int ENOTDIR = Errno .ENOTDIR .intValue ();
28
+ // If you add a constant here, add it below in isExceptionSupported() too.
29
+ protected final static int ENOENT = Errno .ENOENT .intValue ();
30
+ protected final static int EBADF = Errno .EBADF .intValue ();
31
+ protected final static int EEXIST = Errno .EEXIST .intValue ();
32
+ protected final static int EACCES = Errno .EACCES .intValue ();
33
+ protected final static int ENOTDIR = Errno .ENOTDIR .intValue ();
34
+
35
+ public static boolean isExceptionSupported (int errno ) {
36
+ return errno == ENOENT || errno == EBADF || errno == EEXIST || errno == EACCES || errno == ENOTDIR ;
37
+ }
33
38
34
39
public ExceptionErrnoErrorPrimitiveNode (RubyContext context , SourceSection sourceSection ) {
35
40
super (context , sourceSection );
@@ -40,12 +45,12 @@ public RubyException enoent(RubyString message, int errno) {
40
45
return getContext ().getCoreLibrary ().fileNotFoundError (message .toString (), this );
41
46
}
42
47
43
- @ Specialization (guards = {"isNil(message)" , "errno == ENOENT" })
48
+ @ Specialization (guards = { "errno == ENOENT" , "isNil(message)" })
44
49
public RubyException enoent (Object message , int errno ) {
45
50
return getContext ().getCoreLibrary ().fileNotFoundError ("nil" , this );
46
51
}
47
52
48
- @ Specialization (guards = {"isNil(message)" , "errno == EBADF" })
53
+ @ Specialization (guards = { "errno == EBADF" , "isNil(message)" })
49
54
public RubyException ebadf (Object message , int errno ) {
50
55
return getContext ().getCoreLibrary ().badFileDescriptor (this );
51
56
}
@@ -55,7 +60,7 @@ public RubyException eexist(RubyString message, int errno) {
55
60
return getContext ().getCoreLibrary ().fileExistsError (message .toString (), this );
56
61
}
57
62
58
- @ Specialization (guards = {"isNil(message)" , "errno == EEXIST" })
63
+ @ Specialization (guards = { "errno == EEXIST" , "isNil(message)" })
59
64
public RubyException eexist (Object message , int errno ) {
60
65
return getContext ().getCoreLibrary ().fileExistsError ("nil" , this );
61
66
}
@@ -72,32 +77,25 @@ public RubyException enotdir(RubyString message, int errno) {
72
77
73
78
@ CompilerDirectives .TruffleBoundary
74
79
@ Specialization (guards = "!isExceptionSupported(errno)" )
75
- public RubyException unsupported (RubyString message , int errno ) {
80
+ public RubyException unsupported (Object message , int errno ) {
76
81
final Errno errnoObject = Errno .valueOf (errno );
77
82
78
- if (errnoObject == null ) {
79
- throw new UnsupportedOperationException ("errno: " + errno + " " + message );
83
+ final String messageString ;
84
+ if (message instanceof RubyString ) {
85
+ messageString = message .toString ();
86
+ } else if (message == nil ()) {
87
+ messageString = "nil" ;
80
88
} else {
81
- throw new UnsupportedOperationException ( "errno: " + errnoObject . name ()) ;
89
+ messageString = "unsupported message type" ;
82
90
}
83
- }
84
-
85
- @ CompilerDirectives .TruffleBoundary
86
- @ Specialization (guards = {"isNil(message)" , "!isExceptionSupported(errno)" })
87
- public RubyException unsupported (Object message , int errno ) {
88
- final Errno errnoObject = Errno .valueOf (errno );
89
91
90
92
if (errnoObject == null ) {
91
- throw new UnsupportedOperationException ("errno: " + errno + " nil" );
93
+ throw new UnsupportedOperationException ("errno: " + errno + " " + messageString );
92
94
} else {
93
95
throw new UnsupportedOperationException ("errno: " + errnoObject .name ());
94
96
}
95
97
}
96
98
97
- public static boolean isExceptionSupported (int errno ) {
98
- return Errno .ENOENT .intValue () == errno || Errno .EBADF .intValue () == errno || Errno .EEXIST .intValue () == errno || Errno .EACCES .intValue () == errno ;
99
- }
100
-
101
99
}
102
100
103
101
}
0 commit comments