[13.x] Report MultipleRecordsFoundException from sole()#60294
Conversation
|
Wouldn't |
This exception is thrown when calling A HTTP 409, by definition wouldn't fit here as it relates to mutation of data:
Source: https://www.rfc-editor.org/rfc/rfc9110.html#name-409-conflict This would be a Server Error as it's not something the user can resolve and isn't related to mutating data. |
|
But how can "1 too few" be a client error and "1 too many" be something else? Sole doesn't really care about whether its too few or too many—it throws because it is not one, that's the primary reason. |
"Model Not Found" is very different to "Expected 1 as defined, got more". That's why it would need to be a 500. If you're using |
MultipleRecordsFoundException got added to $internalDontReport in #35908 alongside RecordsNotFoundException, but the two aren't really the same kind of error and shouldn't be treated the same way.
RecordsNotFoundException makes sense in that list — prepareException() maps it to a NotFoundHttpException, so it surfaces as a 404. Silencing it from the log is fine, it's the same as any other route model binding miss.
MultipleRecordsFoundException isn't mapped anywhere. It just falls through as an unhandled 500. And because it's in $internalDontReport, nothing gets logged either. So when ->sole() matches more than one row, the user sees a generic 500 and there's no trace of it in the logs, Nightwatch, anywhere.
That's the exact case you'd want to know about. If you called ->sole() you're asserting there's exactly one row — finding two means your data or your query is wrong, and that's a real bug worth reporting. Right now it's getting swallowed.
This PR just removes it from the ignore list. 0 rows still 404s silently via RecordsNotFoundException. 2+ rows now reports like any other uncaught RuntimeException.