Skip to content

Commit

Permalink
Merge pull request #23 from keboola/adamvyborny-CM-646-handle-field-c…
Browse files Browse the repository at this point in the history
…annot-start-exception

Handle field names may not start with $ as user exception
  • Loading branch information
AdamVyborny authored Aug 25, 2023
2 parents 2ad8c33 + 9690100 commit bce23e0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ protected function handleMongoExportFails(Throwable $e): void
throw new UserException('$sort key ordering must be 1 (for ascending) or -1 (for descending)');
}

if (str_contains($e->getMessage(), 'FieldPath field names may not start with \'$\'')) {
throw new UserException('FieldPath field names may not start with \'$\'');
}

if (preg_match('/(Failed:.*?command)/s', $e->getMessage(), $matches)) {
if (isset($matches[1])) {
throw new UserException(trim($matches[1]));
Expand Down
8 changes: 8 additions & 0 deletions tests/phpunit/HandleMongoExportFailsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ public function exceptionsProvider(): Generator
new UserException('Failed: (Unauthorized) not authorized on slotManagementDBTest to ' .
'execute command'),
];

yield 'field names may not start with $' => [
new ProcessFailedException($this->createMockInstanceOfProcess('2023-05-17T12:49:22.079+0000\t' .
'connected to: mongodb+srv://[**REDACTED**]@cl-shared-all-prod-web.x0u5m.mongodb.net/slotManagementDB' .
'2023-05-17T12:49:22.238+0000\tFailed: (Location16410) FieldPath field names may not start with \'$\'' .
'Consider using $getField or $setField.')),
new UserException('FieldPath field names may not start with \'$\''),
];
}

private function createMockInstanceOfProcess(string $errorOutput): Process
Expand Down

0 comments on commit bce23e0

Please sign in to comment.