mirror of
https://github.com/flarum/core.git
synced 2025-10-13 07:54:25 +02:00
error handling when extending flarum from extensions fails (#2740)
This commit is contained in:
30
src/Extension/Exception/ExtensionBootError.php
Normal file
30
src/Extension/Exception/ExtensionBootError.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* For detailed copyright and license information, please view the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Extension\Exception;
|
||||
|
||||
use Exception;
|
||||
use Flarum\Extension\Extension;
|
||||
use Throwable;
|
||||
|
||||
class ExtensionBootError extends Exception
|
||||
{
|
||||
public $extension;
|
||||
public $extender;
|
||||
|
||||
public function __construct(Extension $extension, $extender, Throwable $previous = null)
|
||||
{
|
||||
$this->extension = $extension;
|
||||
$this->extender = $extender;
|
||||
|
||||
$extenderClass = get_class($extender);
|
||||
|
||||
parent::__construct("Experienced an error while booting extension: {$extension->getTitle()}.\n\nError occurred while applying an extender of type: $extenderClass.", null, $previous);
|
||||
}
|
||||
}
|
@@ -11,6 +11,7 @@ namespace Flarum\Extension;
|
||||
|
||||
use Flarum\Database\Migrator;
|
||||
use Flarum\Extend\LifecycleInterface;
|
||||
use Flarum\Extension\Exception\ExtensionBootError;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Contracts\Filesystem\Filesystem as FilesystemInterface;
|
||||
use Illuminate\Contracts\Support\Arrayable;
|
||||
@@ -18,6 +19,7 @@ use Illuminate\Filesystem\Filesystem;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Str;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* @property string $name
|
||||
@@ -50,7 +52,7 @@ class Extension implements Arrayable
|
||||
|
||||
protected static function nameToId($name)
|
||||
{
|
||||
list($vendor, $package) = explode('/', $name);
|
||||
[$vendor, $package] = explode('/', $name);
|
||||
$package = str_replace(['flarum-ext-', 'flarum-'], '', $package);
|
||||
|
||||
return "$vendor-$package";
|
||||
@@ -131,7 +133,11 @@ class Extension implements Arrayable
|
||||
public function extend(Container $container)
|
||||
{
|
||||
foreach ($this->getExtenders() as $extender) {
|
||||
$extender->extend($container, $this);
|
||||
try {
|
||||
$extender->extend($container, $this);
|
||||
} catch (Throwable $e) {
|
||||
throw new ExtensionBootError($this, $extender, $e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user