1
0
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:
Daniël Klabbers
2021-04-29 22:17:41 +02:00
committed by GitHub
parent fcb5778705
commit e0258d2708
3 changed files with 47 additions and 17 deletions

View 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);
}
}

View File

@@ -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);
}
}
}