Skip to content

Commit

Permalink
fix no log write access infinite loop (#1991)
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria authored Aug 25, 2023
1 parent 3dd7dcc commit cc9a6d4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class Handler extends ExceptionHandler
protected $dontReport = [
TokenMismatchException::class,
SessionExpiredException::class,
NoWriteAccessOnLogsExceptions::class,
];

/**
Expand Down Expand Up @@ -399,7 +400,13 @@ public function report(\Throwable $e): void
}
$msg = $msg_ . PHP_EOL . $msg;
} while ($e = $e->getPrevious());
Log::log($severity->value, $msg);
try {
Log::log($severity->value, $msg);
/** @phpstan-ignore-next-line // Yes it is thrown, trust me.... */
} catch (\UnexpectedValueException $e2) {
throw new NoWriteAccessOnLogsExceptions($e2);
// abort(507, 'Could not write in the logs. Check that storage/logs/ and containing files have proper permissions.');
}
}

/**
Expand Down
19 changes: 19 additions & 0 deletions app/Exceptions/NoWriteAccessOnLogsExceptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Exceptions;

use Symfony\Component\HttpFoundation\Response;

/**
* NoWriteAccessOnLogsExceptions.
*
* Indicates any error related to the access rights on the logs.
* Basically we crash because we couldn't write and that create an infinite loop.
*/
class NoWriteAccessOnLogsExceptions extends BaseLycheeException
{
public function __construct(?\Throwable $previous = null)
{
parent::__construct(Response::HTTP_INSUFFICIENT_STORAGE, 'Could not write in the logs. Check that storage/logs/ and containing files have proper permissions.', $previous);
}
}

0 comments on commit cc9a6d4

Please sign in to comment.