Skip to content
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

[9.x] Implement robust handling of forwarding of exception codes #42393

Merged
merged 1 commit into from
May 16, 2022
Merged
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
2 changes: 1 addition & 1 deletion src/Illuminate/Console/Scheduling/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ protected function getDispatcher()
} catch (BindingResolutionException $e) {
throw new RuntimeException(
'Unable to resolve the dispatcher from the service container. Please bind it or install the illuminate/bus package.',
$e->getCode(), $e
is_int($e->getCode()) ? $e->getCode() : 0, $e
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Container/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ public function get(string $id)
throw $e;
}

throw new EntryNotFoundException($id, $e->getCode(), $e);
throw new EntryNotFoundException($id, is_int($e->getCode()) ? $e->getCode() : 0, $e);
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't you assign the result of the function call to save calling it twice when it is an int?

Suggested change
throw new EntryNotFoundException($id, is_int($e->getCode()) ? $e->getCode() : 0, $e);
throw new EntryNotFoundException($id, is_int($code = $e->getCode()) ? $code : 0, $e);

Appreciate this is a very minor optimisation in this case.

}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Concerns/ManagesTransactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected function handleTransactionException(Throwable $e, $currentAttempt, $ma
$this->getName(), $this->transactions
);

throw new DeadlockException($e->getMessage(), (int) $e->getCode(), $e);
throw new DeadlockException($e->getMessage(), is_int($e->getCode()) ? $e->getCode() : 0, $e);
}

// If there was an exception we will rollback this transaction and then we
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function render($request, Throwable $e)

if ($e instanceof NotFoundHttpException) {
throw new NotFoundHttpException(
"{$request->method()} {$request->url()}", $e, $e->getCode()
"{$request->method()} {$request->url()}", $e, is_int($e->getCode()) ? $e->getCode() : 0
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Mail/Transport/SesTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ protected function doSend(SentMessage $message): void
)
);
} catch (AwsException $e) {
throw new Exception('Request to AWS SES API failed.', $e->getCode(), $e);
throw new Exception('Request to AWS SES API failed.', is_int($e->getCode()) ? $e->getCode() : 0, $e);
}

$messageId = $result->get('MessageId');
Expand Down