Skip to content

Commit

Permalink
handle errors
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinGab committed Sep 6, 2024
1 parent 76fdb2f commit 81c5f66
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Services/SearchCode/PhpParserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Closure;
use Elegantly\Translator\Caches\SearchCodeCache;
use Exception;
use Illuminate\Contracts\Filesystem\Filesystem;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\Lang;
Expand Down Expand Up @@ -149,8 +150,15 @@ public function translationsByFiles(
? Blade::compileString($file->getContents())
: $file->getContents();

$translations = static::scanCode($content);

try {
$translations = static::scanCode($content);
} catch (\Throwable $th) {
throw new Exception(
"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.",
code: 422,
previous: $th
);
}
$this->cache?->put($key, $translations);
}

Expand Down

0 comments on commit 81c5f66

Please sign in to comment.