-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Uid] Add value to InvalidArgumentException
#60323
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
[Uid] Add value to InvalidArgumentException
#60323
Conversation
3982cdf
to
f4a50b9
Compare
I challenged adding these properties in the PRs linked in the above description. https://externals.io/message/127188 and https://externals.io/message/127206 might give some food for thoughts on the topic. |
If you want to hear my opinion on these, I think it's reinventing the wheel. There's already established mechanism that developers use for "your input is invalid in a totally predictable way" kind of errors - exceptions. Forasmuch as exceptions are slow, it would make sense to think up the way to make them faster, not to reinvent them. Even though exceptions are somewhat slow, they are not so stupendously slow as database queries, file reads and writes, or any other kind of IO, where PHP just waits for the IO to complete and can nothing in the meantime. I believe that if Edmond doesn't lose faith, it would be solved in the next iterations of True Async. |
Also, don't you think that having the original value of uid that has failed validation in logs is useful? |
@@ -41,7 +41,7 @@ abstract public static function fromString(string $uid): static; | |||
public static function fromBinary(string $uid): static | |||
{ | |||
if (16 !== \strlen($uid)) { | |||
throw new InvalidArgumentException('Invalid binary uid provided.'); | |||
throw new InvalidArgumentException($uid, 'Invalid binary uid provided.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I quickly scanned our code on how we deal in other places with invalid arguments. Having a dedicated argument is something we don't have anywhere else, but we could embed the invalid value in the exception message. That's something we do quite frequently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having a dedicated argument is something we don't have anywhere else
That's a lie.
A lot of exceptions allow passing invalid argument, and expose it.
For example, few exceptions from DependencyInjection
:
DependencyInjection\Exception\AutowiringFailedException
exposes service idDependencyInjection\Exception\ParameterCircularReferenceException
exposes array of parametersDependencyInjection\Exception\ParameterNotFoundException
exposes key, sourceId, sourceKey, alternatives, etcDependencyInjection\Exception\ServiceCircularReferenceException
exposes service idDependencyInjection\Exception\ServiceNotFoundException
exposes service id, and other
And there are at least 40 other distinct exceptions that follow it.
InvalidArgumentException
The failing value is / could be found in the error message, just not in a structured way. Let me 👎 here sorry, I already explained why and I don't see much support from others either so let's move on. |
I don't see much need for accessing the problematic uid either, thanks for proposing. |
[Uid] Add component-specific exception classes ,
[HttpFoundation] Add UriSigner::verify() that throws named exceptions
This PR adds value to Uid-specific InvalidArgumentException.
Thus, anybody who wants to catch the exception, being outside of the scope of the client code, will be able to do so, having the knowledge of what particularly has gone wrong.