@@ -57,32 +57,34 @@ private ExceptionUtils() {
57
57
@ TruffleBoundary
58
58
public static void printPythonLikeStackTrace (Throwable e ) {
59
59
List <TruffleStackTraceElement > stackTrace = TruffleStackTrace .getStackTrace (e );
60
- ArrayList <String > stack = new ArrayList <>();
61
- for (TruffleStackTraceElement frame : stackTrace ) {
60
+ if (stackTrace != null ) {
61
+ ArrayList <String > stack = new ArrayList <>();
62
+ for (TruffleStackTraceElement frame : stackTrace ) {
62
63
63
- StringBuilder sb = new StringBuilder ();
64
- Node location = frame .getLocation ();
65
- SourceSection sourceSection = location != null ? location .getSourceSection () : null ;
66
- String rootName = frame .getTarget ().getRootNode ().getName ();
67
- if (sourceSection != null ) {
68
- sb .append (" " );
69
- String path = sourceSection .getSource ().getPath ();
70
- if (path != null ) {
71
- sb .append ("File " );
64
+ StringBuilder sb = new StringBuilder ();
65
+ Node location = frame .getLocation ();
66
+ SourceSection sourceSection = location != null ? location .getSourceSection () : null ;
67
+ String rootName = frame .getTarget ().getRootNode ().getName ();
68
+ if (sourceSection != null ) {
69
+ sb .append (" " );
70
+ String path = sourceSection .getSource ().getPath ();
71
+ if (path != null ) {
72
+ sb .append ("File " );
73
+ }
74
+ sb .append ('"' );
75
+ sb .append (sourceSection .getSource ().getName ());
76
+ sb .append ("\" , line " );
77
+ sb .append (sourceSection .getStartLine ());
78
+ sb .append (", in " );
79
+ sb .append (rootName );
80
+ stack .add (sb .toString ());
72
81
}
73
- sb .append ('"' );
74
- sb .append (sourceSection .getSource ().getName ());
75
- sb .append ("\" , line " );
76
- sb .append (sourceSection .getStartLine ());
77
- sb .append (", in " );
78
- sb .append (rootName );
79
- stack .add (sb .toString ());
80
82
}
81
- }
82
- System . err . println ( "Traceback (most recent call last):" );
83
- ListIterator < String > listIterator = stack . listIterator ( stack . size ());
84
- while (listIterator .hasPrevious ()) {
85
- System . err . println ( listIterator . previous ());
83
+ System . err . println ( "Traceback (most recent call last):" );
84
+ ListIterator < String > listIterator = stack . listIterator ( stack . size () );
85
+ while ( listIterator . hasPrevious ()) {
86
+ System . err . println (listIterator .previous ());
87
+ }
86
88
}
87
89
System .err .println (e .getMessage ());
88
90
}
0 commit comments