@@ -174,16 +174,7 @@ private Object loadDynamicModuleWithSpec(String name, String path, Node readNode
174
174
} catch (SecurityException | IOException e ) {
175
175
throw raise (ImportError , "cannot load %s: %s" , path , e .getMessage ());
176
176
} 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 );
187
178
}
188
179
TruffleObject pyinitFunc ;
189
180
try {
@@ -207,6 +198,8 @@ private Object loadDynamicModuleWithSpec(String name, String path, Node readNode
207
198
} catch (UnsupportedTypeException | ArityException | UnsupportedMessageException e ) {
208
199
e .printStackTrace ();
209
200
throw raise (ImportError , "cannot initialize %s with PyInit_%s" , path , basename );
201
+ } catch (RuntimeException e ) {
202
+ throw reportImportError (e , path );
210
203
}
211
204
}
212
205
@@ -238,6 +231,19 @@ private SetItemNode getSetItemNode() {
238
231
return setItemNode ;
239
232
}
240
233
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
+
241
247
}
242
248
243
249
@ Builtin (name = "exec_dynamic" , fixedNumOfArguments = 1 )
0 commit comments