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

Conversation

GrahamCampbell
Copy link
Member

@GrahamCampbell GrahamCampbell commented May 15, 2022

getCode(): string|int but __construct(..., int $code, ...). The most sensible thing to do is to attempt to only forward on integer exception codes, and just default back to zero, otherwise. String exception codes (at least ignoring janky 3rd party extensions), can only be found amongst the PHP database exceptions, and for those, we should consider the code to be zero for the purposes of forwarding - casting to 1 doesn't make any sense.

@taylorotwell taylorotwell merged commit 87d1da4 into 9.x May 16, 2022
@taylorotwell taylorotwell deleted the exception-get-code branch May 16, 2022 15:53
@@ -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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants