Skip to content

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

Merged
taylorotwell merged 1 commit into
9.xfrom
exception-get-code
May 16, 2022
Merged

[9.x] Implement robust handling of forwarding of exception codes#42393
taylorotwell merged 1 commit into
9.xfrom
exception-get-code

Conversation

@GrahamCampbell

@GrahamCampbell GrahamCampbell commented May 15, 2022

Copy link
Copy Markdown
Collaborator

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
}

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

Copy link
Copy Markdown
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