Skip to content

Commit 2599f2d

Browse files
authored
Merge pull request OleksiiBulba#12 from OleksiiBulba/chore/nice-exception-messages
Chore: Nice exception messages
2 parents 329f0d7 + b896051 commit 2599f2d

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/Asset/EntrypointLookup.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,21 +102,21 @@ private function getEntriesData(): array
102102
}
103103

104104
if (!file_exists($this->getEntrypointJsonPath())) {
105-
throw new \InvalidArgumentException(sprintf('Could not find the entrypoints file from Webpack: the file "%s" does not exist.', $this->getEntrypointJsonPath()));
105+
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()));
106106
}
107107

108108
try {
109109
$entriesData = $this->decoder->decode(file_get_contents($this->getEntrypointJsonPath()), JsonEncoder::FORMAT);
110110
} catch (UnexpectedValueException $e) {
111-
throw new \InvalidArgumentException(sprintf('There was a problem JSON decoding the "%s" file', $this->getEntrypointJsonPath()), 0, $e);
111+
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);
112112
}
113113

114114
if (!\is_array($entriesData)) {
115-
throw new \InvalidArgumentException(sprintf('There was a problem JSON decoding the "%s" file', $this->getEntrypointJsonPath()));
115+
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()));
116116
}
117117

118118
if (!isset($entriesData['entrypoints'])) {
119-
throw new \InvalidArgumentException(sprintf('Could not find an "entrypoints" key in the "%s" file', $this->getEntrypointJsonPath()));
119+
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()));
120120
}
121121

122122
return $this->entriesData = $entriesData;

tests/unit/Asset/EntrypointLookupTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,25 +277,25 @@ public function invalidArgumentExceptionInGetEntriesDataDataProvider(): array
277277
return [
278278
[
279279
'entrypointFilePath' => '/../fixtures/bad_json',
280-
'expectedExceptionMessageMatches' => '/There was a problem JSON decoding the ".*\/fixtures\/bad_json\/entrypoints.json" file/',
280+
'expectedExceptionMessageMatches' => '/There was a problem JSON decoding the ".*\/fixtures\/bad_json\/entrypoints.json" file\. Try to run npm\/yarn build to fix the issue\./',
281281
'expectedJson' => file_get_contents(__DIR__.'/../fixtures/bad_json/entrypoints.json'),
282282
'decodedJson' => null,
283283
],
284284
[
285285
'entrypointFilePath' => '/../fixtures/no_entrypoint_key',
286-
'expectedExceptionMessageMatches' => '/Could not find an "entrypoints" key in the ".*\/fixtures\/no_entrypoint_key\/entrypoints.json" file/',
286+
'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\./',
287287
'expectedJson' => file_get_contents(__DIR__.'/../fixtures/no_entrypoint_key/entrypoints.json'),
288288
'decodedJson' => ['entrypoint' => []],
289289
],
290290
[
291291
'entrypointFilePath' => '/../fixtures/no_file',
292-
'expectedExceptionMessageMatches' => '/Could not find the entrypoints file from Webpack: the file ".*\/fixtures\/no_file\/entrypoints.json" does not exist\./',
292+
'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?/',
293293
'expectedJson' => '',
294294
'decodedJson' => null,
295295
],
296296
[
297297
'entrypointFilePath' => '/../fixtures/bad_json',
298-
'expectedExceptionMessageMatches' => '/There was a problem JSON decoding the ".*" file/',
298+
'expectedExceptionMessageMatches' => '/There was a problem JSON decoding the ".*" file\. Try to run npm\/yarn build to fix the issue\./',
299299
'expectedJson' => file_get_contents(__DIR__.'/../fixtures/bad_json/entrypoints.json'),
300300
'decodedJson' => null,
301301
],

0 commit comments

Comments
 (0)