mirror of
https://github.com/pelican-dev/panel.git
synced 2025-11-08 14:49:27 +01:00
improve error handling for plugin.json loading
This commit is contained in:
parent
c7c1b8b88c
commit
10dd7b7b47
@ -8,7 +8,9 @@ use Exception;
|
|||||||
use Filament\Forms\Components\Component;
|
use Filament\Forms\Components\Component;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
use Illuminate\Support\Facades\File;
|
use Illuminate\Support\Facades\File;
|
||||||
|
use JsonException;
|
||||||
use Sushi\Sushi;
|
use Sushi\Sushi;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -97,6 +99,7 @@ class Plugin extends Model implements HasPluginSettings
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
$data = File::json($path, JSON_THROW_ON_ERROR);
|
$data = File::json($path, JSON_THROW_ON_ERROR);
|
||||||
|
|
||||||
$panels = null;
|
$panels = null;
|
||||||
@ -132,6 +135,31 @@ class Plugin extends Model implements HasPluginSettings
|
|||||||
];
|
];
|
||||||
|
|
||||||
$plugins[] = $data;
|
$plugins[] = $data;
|
||||||
|
} catch (Exception $exception) {
|
||||||
|
report($exception);
|
||||||
|
|
||||||
|
if (!$exception instanceof JsonException) {
|
||||||
|
$plugins[] = [
|
||||||
|
'id' => $data['id'] ?? Str::uuid(),
|
||||||
|
'name' => $data['name'] ?? 'Invalid Plugin',
|
||||||
|
'author' => $data['author'] ?? 'Unknown',
|
||||||
|
'version' => '0.0.0',
|
||||||
|
'description' => 'Plugin.json is invalid!',
|
||||||
|
'category' => 'invalid',
|
||||||
|
'url' => null,
|
||||||
|
'update_url' => null,
|
||||||
|
'namespace' => 'Error',
|
||||||
|
'class' => 'Error',
|
||||||
|
'panels' => null,
|
||||||
|
'panel_version' => null,
|
||||||
|
'composer_packages' => null,
|
||||||
|
|
||||||
|
'status' => PluginStatus::Errored->value,
|
||||||
|
'status_message' => $exception->getMessage(),
|
||||||
|
'load_order' => 0,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $plugins;
|
return $plugins;
|
||||||
|
|||||||
@ -188,12 +188,14 @@ class PluginService
|
|||||||
$plugin = $plugin instanceof Plugin ? $plugin->id : $plugin;
|
$plugin = $plugin instanceof Plugin ? $plugin->id : $plugin;
|
||||||
$path = plugin_path($plugin, 'plugin.json');
|
$path = plugin_path($plugin, 'plugin.json');
|
||||||
|
|
||||||
|
if (File::exists($path)) {
|
||||||
$pluginData = File::json($path, JSON_THROW_ON_ERROR);
|
$pluginData = File::json($path, JSON_THROW_ON_ERROR);
|
||||||
$metaData = array_merge($pluginData['meta'] ?? [], $data);
|
$metaData = array_merge($pluginData['meta'] ?? [], $data);
|
||||||
$pluginData['meta'] = $metaData;
|
$pluginData['meta'] = $metaData;
|
||||||
|
|
||||||
File::put($path, json_encode($pluginData, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
File::put($path, json_encode($pluginData, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function setStatus(string|Plugin $plugin, PluginStatus $status, ?string $message = null): void
|
private function setStatus(string|Plugin $plugin, PluginStatus $status, ?string $message = null): void
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user