Skip to content

Commit

Permalink
Merge pull request #12 from OleksiiBulba/chore/nice-exception-messages
Browse files Browse the repository at this point in the history
Chore: Nice exception messages
  • Loading branch information
OleksiiBulba authored Jan 9, 2023
2 parents 329f0d7 + b896051 commit 2599f2d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/Asset/EntrypointLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,21 @@ private function getEntriesData(): array
}

if (!file_exists($this->getEntrypointJsonPath())) {
throw new \InvalidArgumentException(sprintf('Could not find the entrypoints file from Webpack: the file "%s" does not exist.', $this->getEntrypointJsonPath()));
throw new \InvalidArgumentException(sprintf('Could not find the entrypoints file from Webpack: the file "%s" does not exist. Maybe you forgot to run npm/yarn build?', $this->getEntrypointJsonPath()));
}

try {
$entriesData = $this->decoder->decode(file_get_contents($this->getEntrypointJsonPath()), JsonEncoder::FORMAT);
} catch (UnexpectedValueException $e) {
throw new \InvalidArgumentException(sprintf('There was a problem JSON decoding the "%s" file', $this->getEntrypointJsonPath()), 0, $e);
throw new \InvalidArgumentException(sprintf('There was a problem JSON decoding the "%s" file. Try to run npm/yarn build to fix the issue.', $this->getEntrypointJsonPath()), 0, $e);
}

if (!\is_array($entriesData)) {
throw new \InvalidArgumentException(sprintf('There was a problem JSON decoding the "%s" file', $this->getEntrypointJsonPath()));
throw new \InvalidArgumentException(sprintf('There was a problem JSON decoding the "%s" file. Try to run npm/yarn build to fix the issue.', $this->getEntrypointJsonPath()));
}

if (!isset($entriesData['entrypoints'])) {
throw new \InvalidArgumentException(sprintf('Could not find an "entrypoints" key in the "%s" file', $this->getEntrypointJsonPath()));
throw new \InvalidArgumentException(sprintf('Could not find an "entrypoints" key in the "%s" file. Try to run npm/yarn build to fix the issue.', $this->getEntrypointJsonPath()));
}

return $this->entriesData = $entriesData;
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/Asset/EntrypointLookupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,25 +277,25 @@ public function invalidArgumentExceptionInGetEntriesDataDataProvider(): array
return [
[
'entrypointFilePath' => '/../fixtures/bad_json',
'expectedExceptionMessageMatches' => '/There was a problem JSON decoding the ".*\/fixtures\/bad_json\/entrypoints.json" file/',
'expectedExceptionMessageMatches' => '/There was a problem JSON decoding the ".*\/fixtures\/bad_json\/entrypoints.json" file\. Try to run npm\/yarn build to fix the issue\./',
'expectedJson' => file_get_contents(__DIR__.'/../fixtures/bad_json/entrypoints.json'),
'decodedJson' => null,
],
[
'entrypointFilePath' => '/../fixtures/no_entrypoint_key',
'expectedExceptionMessageMatches' => '/Could not find an "entrypoints" key in the ".*\/fixtures\/no_entrypoint_key\/entrypoints.json" file/',
'expectedExceptionMessageMatches' => '/Could not find an "entrypoints" key in the ".*\/fixtures\/no_entrypoint_key\/entrypoints.json" file\. Try to run npm\/yarn build to fix the issue\./',
'expectedJson' => file_get_contents(__DIR__.'/../fixtures/no_entrypoint_key/entrypoints.json'),
'decodedJson' => ['entrypoint' => []],
],
[
'entrypointFilePath' => '/../fixtures/no_file',
'expectedExceptionMessageMatches' => '/Could not find the entrypoints file from Webpack: the file ".*\/fixtures\/no_file\/entrypoints.json" does not exist\./',
'expectedExceptionMessageMatches' => '/Could not find the entrypoints file from Webpack: the file ".*\/fixtures\/no_file\/entrypoints.json" does not exist\. Maybe you forgot to run npm\/yarn build?/',
'expectedJson' => '',
'decodedJson' => null,
],
[
'entrypointFilePath' => '/../fixtures/bad_json',
'expectedExceptionMessageMatches' => '/There was a problem JSON decoding the ".*" file/',
'expectedExceptionMessageMatches' => '/There was a problem JSON decoding the ".*" file\. Try to run npm\/yarn build to fix the issue\./',
'expectedJson' => file_get_contents(__DIR__.'/../fixtures/bad_json/entrypoints.json'),
'decodedJson' => null,
],
Expand Down

0 comments on commit 2599f2d

Please sign in to comment.