Skip to content

Commit 8aca895

Browse files
committed
Improve error message
1 parent 980affa commit 8aca895

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/QueryLanguage/Pql/Parser.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,13 @@ private function parseComparison(array &$subQueries): array|ParseResultSubQuery
175175
$this->validateCurrentTokenNotEmpty();
176176

177177
if (!$this->currentToken() || !$this->currentToken()->isA(...self::FIELD_NAME_TOKENS)) {
178-
$this->throwParsingException('a field name', '`' . ($this->currentToken()['value'] ?? 'null') . '`');
178+
$tokenValue = $this->currentToken()['value'] ?? 'null';
179+
$message = null;
180+
if (in_arrayi($tokenValue, ['like', 'not like', 'null', 'empty'])) {
181+
$message = sprintf('Expected %s, found %s.', 'a field name', '`' . $tokenValue . '`')
182+
. ' Reserved keywords cannot be used as field name.';
183+
}
184+
$this->throwParsingException('a field name', '`' . $tokenValue . '`', $message);
179185
}
180186

181187
/** @var Token $fieldToken */

tests/Unit/QueryLanguage/Pql/ParserTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,14 +494,14 @@ public function testParseError9(): void
494494
public function testParseError10(): void
495495
{
496496
$this->expectException(ParsingException::class);
497-
$this->expectExceptionMessage('Expected a field name, found `null`');
497+
$this->expectExceptionMessage('Expected a field name, found `null`. Reserved keywords cannot be used as field name.');
498498
$this->parseQuery('color="red" or null = "foo"');
499499
}
500500

501501
public function testParseError11(): void
502502
{
503503
$this->expectException(ParsingException::class);
504-
$this->expectExceptionMessage('Expected a field name, found `like`');
504+
$this->expectExceptionMessage('Expected a field name, found `like`. Reserved keywords cannot be used as field name.');
505505
$this->parseQuery('color="red" or like = "foo"');
506506
}
507507

0 commit comments

Comments
 (0)