Skip to content
This repository was archived by the owner on Jul 16, 2020. It is now read-only.

Commit 4b192ff

Browse files
eduardor2kmartinlindhe
authored andcommitted
Display error when unable to generate JSON
If language files are malformed, no error will be shown if the JSON conversion fails, generating an empty file.
1 parent 30a2da8 commit 4b192ff

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/Generator.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,12 @@ public function generateFromPath($path, $umd = null, $withVendor = false)
6767
$locales = $this->adjustVendor($locales);
6868

6969
$jsonLocales = json_encode($locales, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . PHP_EOL;
70-
70+
71+
if(json_last_error() !== JSON_ERROR_NONE)
72+
{
73+
throw new Exception('Could not generate JSON, error code '.json_last_error());
74+
}
75+
7176
if (!$umd) {
7277
$jsBody = $this->getES6Module($jsonLocales);
7378
} else {
@@ -122,7 +127,10 @@ public function generateMultiple($path, $umd = null)
122127
$fileToCreate = $jsPath . $fileName . '.js';
123128
$createdFiles .= $fileToCreate . PHP_EOL;
124129
$jsonLocales = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . PHP_EOL;
125-
130+
if(json_last_error() !== JSON_ERROR_NONE)
131+
{
132+
throw new Exception('Could not generate JSON, error code '.json_last_error());
133+
}
126134
if (!$umd) {
127135
$jsBody = $this->getES6Module($jsonLocales);
128136
} else {
@@ -320,4 +328,4 @@ private function getES6Module($body)
320328
{
321329
return "export default {$body}";
322330
}
323-
}
331+
}

0 commit comments

Comments
 (0)