Skip to content

Commit 6a8cd7c

Browse files
committed
[GR-15169] Propagate messages from parser to the user.
PullRequest: graalpython/661
2 parents b8b1ea7 + e29fee9 commit 6a8cd7c

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/parser/PythonParserImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ public String unescapeJavaString(String str) {
259259

260260
private static PException handleParserError(ParserErrorCallback errors, Source source, Exception e) {
261261
SourceSection section = PythonErrorStrategy.getPosition(source, e);
262-
throw errors.raiseInvalidSyntax(source, section);
262+
// from parser we are getting RuntimeExceptions
263+
String message = e instanceof RuntimeException && e.getMessage() != null ? e.getMessage() : "invalid syntax";
264+
throw errors.raiseInvalidSyntax(source, section, message);
263265
}
264266
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/parser/antlr/DescriptiveBailErrorListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol,
6363

6464
String entireMessage = String.format("source: %s, line: %s, index: %s, error message: %s %s",
6565
recognizer.getInputStream().getSourceName(), line, charPositionInLine, msg,
66-
e == null ? "<null>" : e.getMessage());
66+
e == null || e.getMessage() == null ? "invalid syntax" : e.getMessage());
6767

6868
if (e != null) {
6969
PIncompleteSourceException handleRecognitionException = handleRecognitionException(e.getExpectedTokens(), entireMessage, e, line);

0 commit comments

Comments
 (0)