Skip to content

Commit 56f0043

Browse files
committed
Use error message format specifier instead of 'e.getMessage()'.
1 parent bb6de0d commit 56f0043

File tree

9 files changed

+21
-31
lines changed

9 files changed

+21
-31
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ImpModuleBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ private Object loadDynamicModuleWithSpec(String name, String path, InteropLibrar
179179
CallTarget callTarget = env.parse(Source.newBuilder(LLVM_LANGUAGE, env.getTruffleFile(path)).build());
180180
sulongLibrary = (TruffleObject) callTarget.call();
181181
} catch (SecurityException | IOException e) {
182-
throw raise(ImportError, "cannot load %s: %s", path, e.getMessage());
182+
throw raise(ImportError, "cannot load %s: %m", path, e);
183183
} catch (RuntimeException e) {
184184
throw reportImportError(e, path);
185185
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/InteropModuleBuiltins.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ Object evalString(@SuppressWarnings("unused") PNone path, String value, String l
142142
}
143143
return env.parse(newBuilder.build()).call();
144144
} catch (RuntimeException e) {
145-
throw raise(NotImplementedError, e.getMessage());
145+
throw raise(NotImplementedError, e);
146146
}
147147
}
148148

@@ -169,7 +169,7 @@ Object evalFile(String path, @SuppressWarnings("unused") PNone string, String la
169169
} catch (IOException e) {
170170
throw raise(OSError, "%s", e);
171171
} catch (RuntimeException e) {
172-
throw raise(NotImplementedError, e.getMessage());
172+
throw raise(NotImplementedError, e);
173173
}
174174
}
175175

@@ -182,7 +182,7 @@ Object evalFile(String path, @SuppressWarnings("unused") PNone string, @Suppress
182182
} catch (IOException e) {
183183
throw raise(OSError, "%s", e);
184184
} catch (RuntimeException e) {
185-
throw raise(NotImplementedError, e.getMessage());
185+
throw raise(NotImplementedError, e);
186186
}
187187
}
188188

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ private String decode(byte[] raw) {
757757
try {
758758
return new String(raw, "ascii");
759759
} catch (UnsupportedEncodingException e) {
760-
throw raise(PythonBuiltinClassType.UnicodeDecodeError, e.getMessage());
760+
throw raise(PythonBuiltinClassType.UnicodeDecodeError, e);
761761
}
762762
}
763763

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixSubprocessModuleBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ synchronized int forkExec(PList args, @SuppressWarnings("unused") PList execList
157157
throw raise(PythonBuiltinClassType.OSError, "working directory %s is not accessible", cwd);
158158
}
159159
} catch (SecurityException e) {
160-
throw raise(PythonBuiltinClassType.OSError, e.getMessage());
160+
throw raise(PythonBuiltinClassType.OSError, e);
161161
}
162162

163163
Map<String, String> environment = pb.environment();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/TruffleCextBuiltins.java

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -737,17 +737,12 @@ Object doIt(VirtualFrame frame,
737737
context.setCurrentException(exceptionState);
738738
return result;
739739
} catch (UnsupportedTypeException | UnsupportedMessageException e) {
740-
throw context.getCore().raise(PythonBuiltinClassType.TypeError, "Calling native function %s failed: %s", name, getMessage(e));
740+
throw context.getCore().raise(PythonBuiltinClassType.TypeError, "Calling native function %s failed: %m", name, e);
741741
} catch (ArityException e) {
742742
throw context.getCore().raise(PythonBuiltinClassType.TypeError, "Calling native function %s expected %d arguments but got %d.", name, e.getExpectedArity(), e.getActualArity());
743743
}
744744
}
745745

746-
@TruffleBoundary
747-
private static final String getMessage(Throwable e) {
748-
return e.getMessage();
749-
}
750-
751746
private Object fromNative(Object result) {
752747
return fromForeign.executeConvert(result);
753748
}
@@ -833,11 +828,6 @@ protected static ByteBuffer wrap(byte[] data) {
833828
protected static ByteBuffer wrap(byte[] data, int offset, int length) {
834829
return ByteBuffer.wrap(data, offset, length);
835830
}
836-
837-
@TruffleBoundary
838-
protected static String getMessage(Throwable throwable) {
839-
return throwable.getMessage();
840-
}
841831
}
842832

843833
abstract static class NativeUnicodeBuiltin extends NativeBuiltin {
@@ -1007,11 +997,11 @@ Object doBytes(TruffleObject o, long elementSize, Object errorMarker,
1007997
}
1008998
return decoded.toString();
1009999
} catch (CharacterCodingException e) {
1010-
return raiseNative(errorMarker, PythonErrorType.UnicodeError, e.getMessage());
1000+
return raiseNative(errorMarker, PythonErrorType.UnicodeError, "%m", e);
10111001
} catch (IllegalArgumentException e) {
1012-
return raiseNative(errorMarker, PythonErrorType.LookupError, e.getMessage());
1002+
return raiseNative(errorMarker, PythonErrorType.LookupError, "%m", e);
10131003
} catch (InteropException e) {
1014-
return raiseNative(errorMarker, PythonErrorType.TypeError, e.getMessage());
1004+
return raiseNative(errorMarker, PythonErrorType.TypeError, "%m", e);
10151005
}
10161006
}
10171007

@@ -1040,9 +1030,9 @@ Object doBytes(TruffleObject o, Object errorMarker,
10401030
CharBuffer cbuf = decoder.decode(wrap(getByteArrayNode.execute(o, -1)));
10411031
return cbuf.toString();
10421032
} catch (CharacterCodingException e) {
1043-
return raiseNative(errorMarker, PythonErrorType.UnicodeError, e.getMessage());
1033+
return raiseNative(errorMarker, PythonErrorType.UnicodeError, "%m", e);
10441034
} catch (InteropException e) {
1045-
return raiseNative(errorMarker, PythonErrorType.TypeError, e.getMessage());
1035+
return raiseNative(errorMarker, PythonErrorType.TypeError, "%m", e);
10461036
}
10471037
}
10481038
}
@@ -1077,7 +1067,7 @@ Object doUnicode(PString s, String errors, Object error_marker) {
10771067
transformToNative(e);
10781068
return error_marker;
10791069
} catch (CharacterCodingException e) {
1080-
return raiseNative(error_marker, PythonErrorType.UnicodeEncodeError, e.getMessage());
1070+
return raiseNative(error_marker, PythonErrorType.UnicodeEncodeError, "%m", e);
10811071
}
10821072
}
10831073

@@ -1150,12 +1140,12 @@ Object doUnicode(TruffleObject o, long size, String errors, int byteorder, Objec
11501140
CharBuffer decode = decoder.onMalformedInput(action).onUnmappableCharacter(action).decode(wrap(getByteArrayNode.execute(o, size), 0, (int) size));
11511141
return toSulongNode.execute(decode.toString());
11521142
} catch (CharacterCodingException e) {
1153-
return raiseNative(errorMarker, PythonErrorType.UnicodeEncodeError, e.getMessage());
1143+
return raiseNative(errorMarker, PythonErrorType.UnicodeEncodeError, "%m", e);
11541144
} catch (IllegalArgumentException e) {
11551145
String csName = getUTF32Name(byteorder);
11561146
return raiseNative(errorMarker, PythonErrorType.LookupError, "unknown encoding: " + csName);
11571147
} catch (InteropException e) {
1158-
return raiseNative(errorMarker, PythonErrorType.TypeError, e.getMessage());
1148+
return raiseNative(errorMarker, PythonErrorType.TypeError, "%m", e);
11591149
}
11601150
}
11611151
}
@@ -1229,7 +1219,7 @@ Object doUnicode(String s, long elementSize, long elements, Object errorMarker)
12291219
}
12301220
} catch (IllegalArgumentException e) {
12311221
// TODO
1232-
return raiseNative(errorMarker, PythonErrorType.LookupError, e.getMessage());
1222+
return raiseNative(errorMarker, PythonErrorType.LookupError, "%m", e);
12331223
}
12341224
}
12351225

@@ -2156,7 +2146,7 @@ Object doGeneric(Object module, PythonNativeObject object,
21562146
try {
21572147
return factory().createBytes(getByteArrayNode.execute(object.getPtr(), -1));
21582148
} catch (InteropException e) {
2159-
return raiseNative(getNativeNullNode.execute(module), PythonErrorType.TypeError, getMessage(e));
2149+
return raiseNative(getNativeNullNode.execute(module), PythonErrorType.TypeError, "%m", e);
21602150
}
21612151
}
21622152
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ZLibModuleBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ Object decompress(InflaterWrapper stream, PIBytesLike pb, int maxLen) {
501501
try {
502502
bytesWritten = stream.inflater.inflate(result, 0, result.length);
503503
} catch (DataFormatException e) {
504-
throw raise(ZLibError, e.getMessage());
504+
throw raise(ZLibError, e);
505505
}
506506
baos.write(result, 0, bytesWritten);
507507
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ public static PythonAbstractClass[] doSlowPath(Object obj) {
546546
try {
547547
return cast(SequenceStorageNodes.ToArrayNode.doSlowPath(basesTuple.getSequenceStorage()));
548548
} catch (ClassCastException e) {
549-
throw PythonLanguage.getCore().raise(PythonBuiltinClassType.SystemError, "unsupported object in 'tp_bases' (msg: %s)", e.getMessage());
549+
throw PythonLanguage.getCore().raise(PythonBuiltinClassType.SystemError, "unsupported object in 'tp_bases' (msg: %m)", e);
550550
}
551551
}
552552
throw new IllegalStateException("unknown type " + obj.getClass().getName());

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/statement/TryExceptNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ private boolean shouldCatchAll() {
148148

149149
@TruffleBoundary
150150
private PBaseException getBaseException(Exception t) {
151-
return factory().createBaseException(PythonErrorType.ValueError, t.getMessage(), new Object[0]);
151+
return factory().createBaseException(PythonErrorType.ValueError, "%m", new Object[]{t});
152152
}
153153

154154
@ExplodeLoop

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/InternalFormat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ private static Spec fromText(PythonCore core, String text) {
3232
try {
3333
return parser.parse();
3434
} catch (IllegalArgumentException e) {
35-
throw core.raise(ValueError, e.getMessage());
35+
throw core.raise(ValueError, "%m", e);
3636
}
3737
}
3838

0 commit comments

Comments
 (0)