Skip to content

[Debug] Allow flatten throwable #26447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Symfony/Component/Debug/Exception/FlattenException.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class FlattenException
private $file;
private $line;

public static function create(\Exception $exception, $statusCode = null, array $headers = array())
public static function create(\Throwable $exception, $statusCode = null, array $headers = array())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change will break applications that extend this class and override the create method.

{
$e = new static();
$e->setMessage($exception->getMessage());
Expand Down Expand Up @@ -178,7 +178,7 @@ public function getTrace()
return $this->trace;
}

public function setTraceFromException(\Exception $exception)
public function setTraceFromException(\Throwable $exception)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a BC break for the same reasons.

{
$this->setTrace($exception->getTrace(), $exception->getFile(), $exception->getLine());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,24 @@ public function testFlattenHttpException(\Exception $exception)

public function testThrowable()
{
$exception = new FatalThrowableError(new \DivisionByZeroError('Ouch', 42));
$exception = new \DivisionByZeroError('Ouch', 42);
$flattened = FlattenException::create($exception);

$this->assertSame('Ouch', $flattened->getMessage(), 'The message is copied from the original error.');
$this->assertSame(42, $flattened->getCode(), 'The code is copied from the original error.');
$this->assertSame('DivisionByZeroError', $flattened->getClass(), 'The class is set to the class of the original error');
}

public function testFatalThrowableError()
{
$exception = new FatalThrowableError(new \DivisionByZeroError('Ouch', 11));
$flattened = FlattenException::create($exception);

$this->assertSame('Ouch', $flattened->getMessage(), 'The message is copied from the original error.');
$this->assertSame(11, $flattened->getCode(), 'The code is copied from the original error.');
$this->assertSame('DivisionByZeroError', $flattened->getClass(), 'The class is set to the class of the original error');
}

/**
* @dataProvider flattenDataProvider
*/
Expand Down