4
0
mirror of https://github.com/AzuraCast/AzuraCast.git synced 2024-06-14 05:06:37 +00:00

Improve clarity of the error that happens when MariaDB fails to boot.

This commit is contained in:
Buster Neece 2022-11-23 06:40:31 -06:00
parent 4096c9d2a5
commit fe4849521f
No known key found for this signature in database
GPG Key ID: F1D2E64A0005E80E
2 changed files with 49 additions and 42 deletions

View File

@ -6,7 +6,6 @@
use App\Environment;
use App\Event;
use App\Exception;
use Psr\Container\ContainerInterface;
return [
@ -102,7 +101,6 @@ return [
]
);
try {
$mappingClassesPaths = [$environment->getBaseDirectory() . '/src/Entity'];
$buildDoctrineMappingPathsEvent = new Event\BuildDoctrineMappingPaths(
@ -140,17 +138,8 @@ return [
$eventManager->addEventSubscriber($eventChangeTracking);
return new App\Doctrine\DecoratedEntityManager(
function () use (
$connectionOptions,
$config,
$eventManager
) {
return Doctrine\ORM\EntityManager::create($connectionOptions, $config, $eventManager);
}
fn() => Doctrine\ORM\EntityManager::create($connectionOptions, $config, $eventManager)
);
} catch (Exception $e) {
throw new App\Exception\BootstrapException($e->getMessage());
}
},
App\Doctrine\ReloadableEntityManagerInterface::class => DI\Get(App\Doctrine\DecoratedEntityManager::class),

View File

@ -6,6 +6,7 @@ namespace App\Doctrine;
use App\Entity\Interfaces\IdentifiableEntityInterface;
use Closure;
use Doctrine\DBAL\Exception\ConnectionException;
use Doctrine\ORM\Decorator\EntityManagerDecorator;
use Doctrine\ORM\ORMInvalidArgumentException;
@ -16,6 +17,23 @@ final class DecoratedEntityManager extends EntityManagerDecorator implements Rel
public function __construct(callable $createEm)
{
parent::__construct($createEm());
try {
$this->getConnection()->getNativeConnection();
} catch (ConnectionException $e) {
if (2002 === $e->getCode()) {
throw new \Exception(
sprintf(
'Could not connect to the database. Check the error log for additional information. (%s)',
$e->getMessage()
),
$e->getCode()
);
}
throw $e;
}
$this->createEm = $createEm(...);
}