Skip to content

Commit 31afa3a

Browse files
committed
Avoid usage of context in PBaseException.toString
1 parent b750ee4 commit 31afa3a

File tree

1 file changed

+12
-1
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception

1 file changed

+12
-1
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/PBaseException.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,18 @@ public String getFormattedMessage(PythonObjectLibrary lib) {
228228
@Override
229229
public String toString() {
230230
CompilerAsserts.neverPartOfCompilation();
231-
return getFormattedMessage(PythonObjectLibrary.getUncached());
231+
// We *MUST NOT* call anything here that may need a context!
232+
StringBuilder sb = new StringBuilder(GetLazyPythonClass.getInitialClass(this).toString());
233+
if (messageArgs != null && messageArgs.length > 0) {
234+
sb.append("(fmt=\"").append(messageFormat).append("\", args = (");
235+
for (Object arg : messageArgs) {
236+
sb.append(arg).append(", ");
237+
}
238+
sb.append(") )");
239+
} else if (hasMessageFormat) {
240+
sb.append("(fmt=\"").append(messageFormat).append('"');
241+
}
242+
return sb.toString();
232243
}
233244

234245
public LazyTraceback internalReifyException(PFrame.Reference curFrameInfo) {

0 commit comments

Comments
 (0)