Skip to content
This repository was archived by the owner on Jun 26, 2022. It is now read-only.

Commit cf36798

Browse files
authored
Fix error messages being duplicated (#5)
## What is the goal of this PR? Previously, when parsing a query failed with an error, on converting the resulting error object to a string, the string would contain two copies of the error message - e.g: ``` [GQL03] TypeQL Error: There is a syntax error at line 1: match $x sb thing; ^ no viable alternative at input 'match $x sb' [GQL03] TypeQL Error: There is a syntax error at line 1: match $x sb thing; ^ no viable alternative at input 'match $x sb' ``` This is now fixed and error messages are no longer duplicated. (Also, the error code is now TQL) ## What are the changes implemented in this PR? - Fix error messages being duplicated (fixes #4) - Change error code from GQL to TQL
1 parent fdd2b00 commit cf36798

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

common/exception/ErrorMessage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public class ErrorMessage extends com.vaticle.typedb.common.exception.ErrorMessa
105105
new ErrorMessage(40, "'%s' is not a valid Type label. Type labels must start with a letter, and may contain only letters, numbers, '-' and '_'.");
106106

107107

108-
private static final String codePrefix = "GQL";
108+
private static final String codePrefix = "TQL";
109109
private static final String messagePrefix = "TypeQL Error";
110110

111111
public ErrorMessage(int codeNumber, String messageBody) {

parser/ErrorListener.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ public boolean hasErrors() {
7474
return !errors.isEmpty();
7575
}
7676

77+
public void clearErrors() {
78+
errors.clear();
79+
}
80+
7781
@Override
7882
public String toString() {
7983
return errors.stream().map(SyntaxError::toString).collect(Collectors.joining("\n"));

parser/Parser.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ private <CONTEXT extends ParserRuleContext, RETURN> RETURN parse(
136136
// DefaultErrorStrategy + LL_EXACT_AMBIG_DETECTION
137137
// This was not set to default parsing strategy, but it is useful
138138
// to produce detailed/useful error message
139+
errorListener.clearErrors();
139140
parser.setErrorHandler(new DefaultErrorStrategy());
140141
parser.getInterpreter().setPredictionMode(PredictionMode.LL_EXACT_AMBIG_DETECTION);
141142
queryContext = parserMethod.apply(parser);

0 commit comments

Comments
 (0)