Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
bakerkretzmar committed Nov 21, 2022
1 parent 493d2c9 commit a458632
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 31 deletions.
4 changes: 2 additions & 2 deletions src/Bootstrap/HandleExceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ private function handleDeprecation(Throwable $e): void
/**
* Handle an uncaught exception from the application.
*
* Note: Most exceptions can be handled via the try / catch block
* in the kernel, but fatal error exceptions must be handled
* Note: Most exceptions can be handled in a try / catch block higher
* in the app, but fatal error exceptions must be handled
* differently since they are not normal exceptions.
*/
private function handleException(Throwable $e): void
Expand Down
54 changes: 25 additions & 29 deletions src/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,6 @@ class Handler implements ExceptionHandler
/** @var array<string, Closure> */
private array $exceptionMap = [];

public function map(Closure|string $from, Closure|string|null $to = null): static
{
if (is_string($to)) {
$to = fn ($exception) => new $to('', 0, $exception);
}

if (is_callable($from) && is_null($to)) {
$from = $this->firstClosureParameterType($to = $from);
}

if (! is_string($from) || ! $to instanceof Closure) {
throw new InvalidArgumentException('Invalid exception mapping.');
}

$this->exceptionMap[$from] = $to;

return $this;
}

public function report(Throwable $e): void
{
//
Expand All @@ -67,14 +48,10 @@ public function renderForConsole($output, Throwable $e): void
$message = str($e->getMessage())->explode('.')->first();

if (! empty($alternatives = $e->getAlternatives())) {
$message .= '. Did you mean one of these?';

with(new Error($output))->render($message);
with(new BulletList($output))->render($e->getAlternatives());

$output->writeln('');
(new Error($output))->render("{$message}. Did you mean one of these?");
(new BulletList($output))->render($alternatives);
} else {
with(new Error($output))->render($message);
(new Error($output))->render($message);
}

return;
Expand All @@ -87,15 +64,15 @@ public function renderForConsole($output, Throwable $e): void
}

if ($e instanceof DeprecationException) {
// If the exception appears to have come from a compiled Blade view, wrap it
// in a ViewException and map it so Ignition will add the uncompiled path
// If the deprecation appears to have come from a compiled Blade view, wrap it in
// a ViewException and map it manually so Ignition will add the uncompiled path
if (preg_match('/cache\/\w+\.php$/', $e->getFile()) === 1) {
$e = $this->mapException(
new ViewException("{$e->getMessage()} (View: )", 0, 1, $e->getFile(), $e->getLine(), $e),
);
}

with(new Warn($output))->render("{$e->getMessage()} in {$e->getFile()} on line {$e->getLine()}");
(new Warn($output))->render("{$e->getMessage()} in {$e->getFile()} on line {$e->getLine()}");

return;
}
Expand All @@ -111,6 +88,25 @@ public function renderForConsole($output, Throwable $e): void
$handler->handle();
}

public function map(Closure|string $from, Closure|string|null $to = null): static
{
if (is_string($to)) {
$to = fn ($exception) => new $to('', 0, $exception);
}

if (is_callable($from) && is_null($to)) {
$from = $this->firstClosureParameterType($to = $from);
}

if (! is_string($from) || ! $to instanceof Closure) {
throw new InvalidArgumentException('Invalid exception mapping.');
}

$this->exceptionMap[$from] = $to;

return $this;
}

protected function mapException(Throwable $e): Throwable
{
if (method_exists($e, 'getInnerException') && ($inner = $e->getInnerException()) instanceof Throwable) {
Expand Down

0 comments on commit a458632

Please sign in to comment.