Skip to content

Commit 81c5f66

Browse files
committed
handle errors
1 parent 76fdb2f commit 81c5f66

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/Services/SearchCode/PhpParserService.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Closure;
66
use Elegantly\Translator\Caches\SearchCodeCache;
7+
use Exception;
78
use Illuminate\Contracts\Filesystem\Filesystem;
89
use Illuminate\Support\Facades\Blade;
910
use Illuminate\Support\Facades\Lang;
@@ -149,8 +150,15 @@ public function translationsByFiles(
149150
? Blade::compileString($file->getContents())
150151
: $file->getContents();
151152

152-
$translations = static::scanCode($content);
153-
153+
try {
154+
$translations = static::scanCode($content);
155+
} catch (\Throwable $th) {
156+
throw new Exception(
157+
"File can't be parsed: {$file->getPath()}. Your file might contain a syntax error. You can either fix the file or add it to the ignored path.",
158+
code: 422,
159+
previous: $th
160+
);
161+
}
154162
$this->cache?->put($key, $translations);
155163
}
156164

0 commit comments

Comments
 (0)