Skip to content

Commit 2b4e691

Browse files
committed
[bugfix] Preserve the Error Code from the initial XQuery parser stage
1 parent b7ee7d3 commit 2b4e691

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

exist-core/src/main/antlr/org/exist/xquery/parser/XQuery.g

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ options {
103103
return buf.toString();
104104
}
105105
106+
public Exception getLastException() {
107+
return (Exception) exceptions.get(exceptions.size() - 1);
108+
}
109+
106110
public String getXQDoc() {
107111
return lexer.getXQDoc();
108112
}

exist-core/src/main/java/org/exist/xquery/XQuery.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,18 @@ private CompiledXQuery compile(final XQueryContext context, final Reader reader,
224224
} else {
225225
parser.xpath();
226226
}
227-
228-
if(parser.foundErrors()) {
229-
LOG.debug(parser.getErrorMessage());
230-
throw new StaticXQueryException(context.getRootExpression(), parser.getErrorMessage());
227+
228+
if (parser.foundErrors()) {
229+
if (LOG.isDebugEnabled()) {
230+
LOG.debug(parser.getErrorMessage());
231+
}
232+
final Exception lastException = parser.getLastException();
233+
if (lastException != null && lastException instanceof XPathException) {
234+
final XPathException xpe = (XPathException) lastException;
235+
throw new StaticXQueryException(xpe.getColumn(), xpe.getLine(), parser.getErrorMessage(), xpe);
236+
} else {
237+
throw new StaticXQueryException(context.getRootExpression(), parser.getErrorMessage());
238+
}
231239
}
232240

233241
final AST ast = parser.getAST();

0 commit comments

Comments
 (0)