add exception trace on debug mode

This commit is contained in:
Simon Vieille 2024-02-21 19:29:02 +01:00
parent 3b643ccd64
commit 961034266b
Signed by: deblan
GPG key ID: 579388D585F70417
2 changed files with 18 additions and 11 deletions

View file

@ -103,13 +103,23 @@ function writeln(...$values)
}
}
function handleError($section, Exception $e)
function handleError($section, Exception $e, bool $debug)
{
writeln(
sprintf('ERROR - %s', $section),
$e->getMessage()
);
if ($debug) {
writeln(
"",
"Trace",
"=====",
json_encode($e->getTrace(), JSON_PRETTY_PRINT),
"=====",
);
}
exit(1);
}
@ -117,11 +127,8 @@ if ($config['is_debug']) {
writeln(
'Debug',
'=====',
'Config',
json_encode($config, JSON_PRETTY_PRINT),
'Environment',
json_encode($_SERVER, JSON_PRETTY_PRINT),
'====='
json_encode(['config' => $config, 'environment' => $_SERVER], JSON_PRETTY_PRINT),
'=====',
);
}
@ -141,11 +148,11 @@ try {
writeln('Email sent!');
}
} catch (SyntaxError $e) {
handleError('Syntax error', $e);
handleError('Syntax error', $e, $config['is_debug']);
} catch (TransportException $e) {
handleError('Transport error', $e);
handleError('Transport error', $e, $config['is_debug']);
} catch (RfcComplianceException $e) {
handleError('RFC compliance error', $e);
handleError('RFC compliance error', $e, $config['is_debug']);
} catch (\Exception $e) {
handleError('Generic error', $e);
handleError('Generic error', $e, $config['is_debug']);
}

View file

@ -21,7 +21,7 @@ class EmailFactory
public function createMailer(): Mailer
{
return new Mailer(Transport::fromDsn($this->config['dsn']));
return new Mailer(Transport::fromDsn((string) $this->config['dsn']));
}
public function createEmail(): Email