Skip to content

Commit

Permalink
rename SearchQueryErrorCode error codes
Browse files Browse the repository at this point in the history
  • Loading branch information
williamcotton committed Dec 11, 2024
1 parent 1b7fb97 commit d096229
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 149 deletions.
3 changes: 1 addition & 2 deletions search-input-query-parser/src/first-pass-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,11 @@ export const parseExpression = (

const operator = token.type;
const nextStream = advanceStream(result.stream);

const nextToken = currentToken(nextStream);
if (nextToken.type === TokenType.EOF) {
throw {
message: `Unexpected token: ${token.value}`,
code: SearchQueryErrorCode.UNEXPECTED_TOKEN,
code: SearchQueryErrorCode.SYNTAX_TOKEN_UNEXPECTED,
value: token.value,
position: token.position,
length: token.length,
Expand Down
6 changes: 3 additions & 3 deletions search-input-query-parser/src/lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const tokenizeQuotedString = (

throw {
message: "Unterminated quoted string",
code: SearchQueryErrorCode.UNTERMINATED_QUOTED_STRING,
code: SearchQueryErrorCode.SYNTAX_QUOTE_UNTERMINATED,
position,
length,
};
Expand Down Expand Up @@ -324,7 +324,7 @@ export const tokenize = (input: string): Token[] => {
throw {
message:
"Invalid syntax: Missing operator or whitespace between terms",
code: SearchQueryErrorCode.MISSING_OPERATOR_OR_WHITESPACE,
code: SearchQueryErrorCode.SYNTAX_OPERATOR_OR_SPACE_MISSING,
position: position,
length: 1,
};
Expand All @@ -341,7 +341,7 @@ export const tokenize = (input: string): Token[] => {
throw {
message:
"Invalid syntax: Missing operator or whitespace between terms",
code: SearchQueryErrorCode.MISSING_OPERATOR_OR_WHITESPACE,
code: SearchQueryErrorCode.SYNTAX_OPERATOR_OR_SPACE_MISSING,
position: newPos,
length: 1,
};
Expand Down
8 changes: 4 additions & 4 deletions search-input-query-parser/src/parse-in-values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const parseInValues = (
if (currentToken(currentStream).type !== TokenType.LPAREN) {
throw {
message: "Expected '(' after IN",
code: SearchQueryErrorCode.EXPECTED_LPAREN_AFTER_IN,
code: SearchQueryErrorCode.IN_LPAREN_MISSING,
position: inValuePosition, // Use the position passed from the caller
length: 1,
};
Expand All @@ -27,7 +27,7 @@ export const parseInValues = (
if (values.length === 0) {
throw {
message: "IN operator requires at least one value",
code: SearchQueryErrorCode.EMPTY_IN_LIST,
code: SearchQueryErrorCode.IN_LIST_EMPTY,
position: token.position,
length: 1,
};
Expand All @@ -45,7 +45,7 @@ export const parseInValues = (
token.type !== TokenType.COMMA)) {
throw {
message: "Expected ',' or ')' after IN value",
code: SearchQueryErrorCode.EXPECTED_IN_SEPARATOR,
code: SearchQueryErrorCode.IN_SEPARATOR_MISSING,
position: token.position,
length: 1,
};
Expand All @@ -67,7 +67,7 @@ export const parseInValues = (
}
throw {
message: "Expected ',' or ')' after IN value",
code: SearchQueryErrorCode.EXPECTED_IN_SEPARATOR,
code: SearchQueryErrorCode.IN_SEPARATOR_MISSING,
position: nextToken.position,
length: 1,
};
Expand Down
8 changes: 4 additions & 4 deletions search-input-query-parser/src/parse-primary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const expectToken = (
if (token.type !== type) {
throw {
message: message ? message : `Expected ${type}`,
code: SearchQueryErrorCode.EXPECTED_TOKEN,
code: SearchQueryErrorCode.SYNTAX_TOKEN_MISSING,
value: type,
position: token.position,
length: token.length,
Expand Down Expand Up @@ -161,7 +161,7 @@ export const parsePrimary = (
case TokenType.OR:
throw {
message: `${token.value} is a reserved word`,
code: SearchQueryErrorCode.RESERVED_WORD,
code: SearchQueryErrorCode.SYNTAX_KEYWORD_RESERVED,
value: token.value,
position: token.position,
length: token.length,
Expand All @@ -170,15 +170,15 @@ export const parsePrimary = (
case TokenType.RPAREN:
throw {
message: 'Unexpected ")"',
code: SearchQueryErrorCode.UNEXPECTED_RIGHT_PAREN,
code: SearchQueryErrorCode.SYNTAX_PARENTHESIS_UNEXPECTED,
position: token.position,
length: token.length,
};

default:
throw {
message: "Unexpected token",
code: SearchQueryErrorCode.UNEXPECTED_TOKEN,
code: SearchQueryErrorCode.SYNTAX_TOKEN_UNEXPECTED,
position: token.position,
length: token.length,
};
Expand Down
Loading

0 comments on commit d096229

Please sign in to comment.