Skip to content

Commit

Permalink
bug #35464 [ErrorHandler] Add debug argument to decide whether debug …
Browse files Browse the repository at this point in the history
…page is shown or not (yceruto)

This PR was merged into the 4.4 branch.

Discussion
----------

[ErrorHandler] Add debug argument to decide whether debug page is shown or not

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #35448
| License       | MIT
| Doc PR        | -

This ensures that the debug page (with stack trace) won't be (by default) displayed in non-CLI context when an early error occurs (after FB::boot()) in non-debug mode (prod). And `Debug::enable()` will enable it explicitly.

Commits
-------

cf80224 Added debug argument to decide if debug page should be shown or not
  • Loading branch information
nicolas-grekas committed Jan 27, 2020
2 parents ef8b34c + cf80224 commit c956d62
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Symfony/Component/ErrorHandler/Debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public static function enable(): ErrorHandler

DebugClassLoader::enable();

return ErrorHandler::register(new ErrorHandler(new BufferingLogger()));
return ErrorHandler::register(new ErrorHandler(new BufferingLogger(), true));
}
}
6 changes: 4 additions & 2 deletions src/Symfony/Component/ErrorHandler/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class ErrorHandler
private $screamedErrors = 0x55; // E_ERROR + E_CORE_ERROR + E_COMPILE_ERROR + E_PARSE
private $loggedErrors = 0;
private $traceReflector;
private $debug;

private $isRecursive = 0;
private $isRoot = false;
Expand Down Expand Up @@ -180,14 +181,15 @@ public static function call(callable $function, ...$arguments)
}
}

public function __construct(BufferingLogger $bootstrappingLogger = null)
public function __construct(BufferingLogger $bootstrappingLogger = null, bool $debug = false)
{
if ($bootstrappingLogger) {
$this->bootstrappingLogger = $bootstrappingLogger;
$this->setDefaultLogger($bootstrappingLogger);
}
$this->traceReflector = new \ReflectionProperty('Exception', 'trace');
$this->traceReflector->setAccessible(true);
$this->debug = $debug;
}

/**
Expand Down Expand Up @@ -697,7 +699,7 @@ public static function handleFatalError(array $error = null): void
*/
private function renderException(\Throwable $exception): void
{
$renderer = \in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) ? new CliErrorRenderer() : new HtmlErrorRenderer(0 !== $this->scopedErrors);
$renderer = \in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) ? new CliErrorRenderer() : new HtmlErrorRenderer($this->debug);

$exception = $renderer->render($exception);

Expand Down

0 comments on commit c956d62

Please sign in to comment.