Skip to content

Commit fe71826

Browse files
committed
Import error reporting during native module initialization.
1 parent 1afdab3 commit fe71826

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,7 @@ private Object loadDynamicModuleWithSpec(String name, String path, Node readNode
174174
} catch (SecurityException | IOException e) {
175175
throw raise(ImportError, "cannot load %s: %s", path, e.getMessage());
176176
} catch (RuntimeException e) {
177-
StringBuilder sb = new StringBuilder();
178-
sb.append(e.getMessage());
179-
Throwable cause = e;
180-
while ((cause = cause.getCause()) != null) {
181-
if (cause.getMessage() != null) {
182-
sb.append(", ");
183-
sb.append(cause.getMessage());
184-
}
185-
}
186-
throw raise(ImportError, "cannot load %s: %s", path, sb.toString());
177+
throw reportImportError(e, path);
187178
}
188179
TruffleObject pyinitFunc;
189180
try {
@@ -207,6 +198,8 @@ private Object loadDynamicModuleWithSpec(String name, String path, Node readNode
207198
} catch (UnsupportedTypeException | ArityException | UnsupportedMessageException e) {
208199
e.printStackTrace();
209200
throw raise(ImportError, "cannot initialize %s with PyInit_%s", path, basename);
201+
} catch (RuntimeException e) {
202+
throw reportImportError(e, path);
210203
}
211204
}
212205

@@ -238,6 +231,19 @@ private SetItemNode getSetItemNode() {
238231
return setItemNode;
239232
}
240233

234+
private PException reportImportError(RuntimeException e, String path) {
235+
StringBuilder sb = new StringBuilder();
236+
sb.append(e.getMessage());
237+
Throwable cause = e;
238+
while ((cause = cause.getCause()) != null) {
239+
if (cause.getMessage() != null) {
240+
sb.append(", ");
241+
sb.append(cause.getMessage());
242+
}
243+
}
244+
return raise(ImportError, "cannot load %s: %s", path, sb.toString());
245+
}
246+
241247
}
242248

243249
@Builtin(name = "exec_dynamic", fixedNumOfArguments = 1)

0 commit comments

Comments
 (0)