Skip to content

Commit

Permalink
Correctly output error with CLI SAPI
Browse files Browse the repository at this point in the history
During handling of an exception in CLI mode the exception handler
called `$this->buildView(…)`, leading to an exception of type
`InvalidTemplateResourceException`.

Now the code is aligned to the `DebugExceptionHandler` and calls
`$this->echoExceptionCli(…)` instead.

Fixes flownative/beach#483
  • Loading branch information
kdambekalns committed Jul 4, 2022
1 parent ff25743 commit a881168
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions Classes/Exception/ProductionExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,26 @@ public function handleException($exception)

$this->renderingOptions = $this->resolveCustomRenderingOptions($exception);

$exceptionWasLogged = false;
if ($this->throwableStorage instanceof ThrowableStorageInterface && isset($this->renderingOptions['logException']) && $this->renderingOptions['logException']) {
$message = $this->throwableStorage->logThrowable($exception);
$this->logger->critical($message);
$exceptionWasLogged = true;
}

try {
if ($sentryClient = self::getSentryClient()) {
$sentryClient->captureThrowable($exception);
}
} catch (\Throwable $e) {
}

switch (PHP_SAPI) {
case 'cli':
try {
if ($sentryClient = self::getSentryClient()) {
$sentryClient->captureThrowable($exception);
}
} catch (\Throwable $e) {
}
echo $this->buildView($exception, $this->renderingOptions)->render();
# Doesn't return:
$this->echoExceptionCli($exception, $exceptionWasLogged);
break;
default:
try {
if ($sentryClient = self::getSentryClient()) {
$sentryClient->captureThrowable($exception);
}
} catch (\Throwable $e) {
}
$this->echoExceptionWeb($exception);
}
}
Expand Down

0 comments on commit a881168

Please sign in to comment.