@@ -1045,29 +1045,32 @@ static final class SyntaxErrData {
1045
1045
final int lineNo ;
1046
1046
final int offset ;
1047
1047
final Object text ;
1048
+ final boolean err ;
1048
1049
1049
- SyntaxErrData (Object message , Object fileName , int lineNo , int offset , Object text ) {
1050
+ SyntaxErrData (Object message , Object fileName , int lineNo , int offset , Object text , boolean err ) {
1050
1051
this .message = message ;
1051
1052
this .fileName = fileName ;
1052
1053
this .lineNo = lineNo ;
1053
1054
this .offset = offset ;
1054
1055
this .text = text ;
1056
+ this .err = err ;
1055
1057
}
1056
1058
}
1057
1059
1058
1060
private SyntaxErrData parseSyntaxError (VirtualFrame frame , Object err ) {
1059
- String msg , fileName = null , text = null ;
1060
- int lineNo = 0 , offset = 0 , hold = 0 ;
1061
+ Object v , msg ;
1062
+ String fileName = null , text = null ;
1063
+ int lineNo = 0 , offset = 0 , hold ;
1061
1064
1062
1065
// new style errors. `err' is an instance
1063
- msg = objectLookupAttrAsString (frame , err , ATTR_MSG );
1064
- if (msg == null ) {
1065
- return new SyntaxErrData (msg , fileName , lineNo , offset , text );
1066
+ msg = objectLookupAttr (frame , err , ATTR_MSG );
1067
+ if (msg == PNone . NO_VALUE ) {
1068
+ return new SyntaxErrData (null , fileName , lineNo , offset , text , true );
1066
1069
}
1067
1070
1068
- Object v = objectLookupAttr (frame , err , ATTR_FILENAME );
1071
+ v = objectLookupAttr (frame , err , ATTR_FILENAME );
1069
1072
if (v == PNone .NO_VALUE ) {
1070
- return new SyntaxErrData (msg , fileName , lineNo , offset , text );
1073
+ return new SyntaxErrData (msg , fileName , lineNo , offset , text , true );
1071
1074
}
1072
1075
if (v == PNone .NONE ) {
1073
1076
fileName = VALUE_STRING ;
@@ -1077,42 +1080,42 @@ private SyntaxErrData parseSyntaxError(VirtualFrame frame, Object err) {
1077
1080
1078
1081
v = objectLookupAttr (frame , err , ATTR_LINENO );
1079
1082
if (v == PNone .NO_VALUE ) {
1080
- return new SyntaxErrData (msg , fileName , lineNo , offset , text );
1083
+ return new SyntaxErrData (msg , fileName , lineNo , offset , text , true );
1081
1084
}
1082
1085
try {
1083
1086
hold = longAsInt (frame , v );
1084
1087
} catch (PException pe ) {
1085
- return new SyntaxErrData (msg , fileName , lineNo , offset , text );
1088
+ return new SyntaxErrData (msg , fileName , lineNo , offset , text , true );
1086
1089
}
1087
1090
1088
1091
lineNo = hold ;
1089
1092
1090
1093
v = objectLookupAttr (frame , err , ATTR_OFFSET );
1091
1094
if (v == PNone .NO_VALUE ) {
1092
- return new SyntaxErrData (msg , fileName , lineNo , offset , text );
1095
+ return new SyntaxErrData (msg , fileName , lineNo , offset , text , true );
1093
1096
}
1094
1097
if (v == PNone .NONE ) {
1095
1098
offset = -1 ;
1096
1099
} else {
1097
1100
try {
1098
1101
hold = longAsInt (frame , v );
1099
1102
} catch (PException pe ) {
1100
- return new SyntaxErrData (msg , fileName , lineNo , offset , text );
1103
+ return new SyntaxErrData (msg , fileName , lineNo , offset , text , true );
1101
1104
}
1102
1105
offset = hold ;
1103
1106
}
1104
1107
1105
1108
v = objectLookupAttr (frame , err , ATTR_TEXT );
1106
1109
if (v == PNone .NO_VALUE ) {
1107
- return new SyntaxErrData (msg , fileName , lineNo , offset , text );
1110
+ return new SyntaxErrData (msg , fileName , lineNo , offset , text , true );
1108
1111
}
1109
1112
if (v == PNone .NONE ) {
1110
1113
text = null ;
1111
1114
} else {
1112
1115
text = castToString (v );
1113
1116
}
1114
1117
1115
- return new SyntaxErrData (msg , fileName , lineNo , offset , text );
1118
+ return new SyntaxErrData (msg , fileName , lineNo , offset , text , false );
1116
1119
}
1117
1120
1118
1121
private void printErrorText (VirtualFrame frame , Object out , SyntaxErrData syntaxErrData ) {
@@ -1200,14 +1203,16 @@ protected void printException(VirtualFrame frame, PythonModule sys, Object out,
1200
1203
if (objectHasAttr (frame , value , ATTR_PRINT_FILE_AND_LINE )) {
1201
1204
// SyntaxError case
1202
1205
final SyntaxErrData syntaxErrData = parseSyntaxError (frame , value );
1203
- value = syntaxErrData .message ;
1204
- StringBuilder sb = PythonUtils .newStringBuilder (" File \" " );
1205
- PythonUtils .append (sb , castToString (objectStr (frame , syntaxErrData .fileName )), "\" , line " , syntaxErrData .lineNo , "\n " );
1206
- fileWriteString (frame , out , PythonUtils .sbToString (sb ));
1207
-
1208
- // Can't be bothered to check all those PyFile_WriteString() calls
1209
- if (syntaxErrData .text != null ) {
1210
- printErrorText (frame , out , syntaxErrData );
1206
+ if (!syntaxErrData .err ) {
1207
+ value = syntaxErrData .message ;
1208
+ StringBuilder sb = PythonUtils .newStringBuilder (" File \" " );
1209
+ PythonUtils .append (sb , castToString (objectStr (frame , syntaxErrData .fileName )), "\" , line " , syntaxErrData .lineNo , "\n " );
1210
+ fileWriteString (frame , out , PythonUtils .sbToString (sb ));
1211
+
1212
+ // Can't be bothered to check all those PyFile_WriteString() calls
1213
+ if (syntaxErrData .text != null ) {
1214
+ printErrorText (frame , out , syntaxErrData );
1215
+ }
1211
1216
}
1212
1217
}
1213
1218
0 commit comments