Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Closed

Conversation

rela589n
Copy link
Contributor

@rela589n rela589n commented May 2, 2025

Q A
Branch? 7.3
Bug fix? no
New feature? yes
Deprecations? no
Follows symfony/symfony-docs#20900 ,
[Uid] Add component-specific exception classes ,
[HttpFoundation] Add UriSigner::verify() that throws named exceptions
License MIT

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.

@rela589n rela589n force-pushed the feat-invalid-argument-exception-value branch from 3982cdf to f4a50b9 Compare May 2, 2025 07:12
@nicolas-grekas
Copy link
Member

nicolas-grekas commented May 4, 2025

I challenged adding these properties in the PRs linked in the above description.
I'm still skeptical about adding them as I don't think reporting back the failing values as structured data belongs to the "exceptions" domain. This feels more like signaling, and clearly that's not what exceptions are for, even if they can be used for this, but in a hacky way IMHO.

https://externals.io/message/127188 and https://externals.io/message/127206 might give some food for thoughts on the topic.

@rela589n
Copy link
Contributor Author

rela589n commented May 5, 2025

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.

@rela589n
Copy link
Contributor Author

rela589n commented May 5, 2025

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.');
Copy link
Member

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.

Copy link
Contributor Author

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 id
  • DependencyInjection\Exception\ParameterCircularReferenceException exposes array of parameters
  • DependencyInjection\Exception\ParameterNotFoundException exposes key, sourceId, sourceKey, alternatives, etc
  • DependencyInjection\Exception\ServiceCircularReferenceException exposes service id
  • DependencyInjection\Exception\ServiceNotFoundException exposes service id, and other

And there are at least 40 other distinct exceptions that follow it.

@xabbuh xabbuh added the ❄️ Feature Freeze Important Pull Requests to finish before the next Symfony "feature freeze" label May 5, 2025
@OskarStark OskarStark changed the title [Uid] add value to InvalidArgumentException [Uid] Add value to InvalidArgumentException May 5, 2025
@nicolas-grekas
Copy link
Member

nicolas-grekas commented May 9, 2025

Also, don't you think that having the original value of uid that has failed validation in logs is useful?

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.

@chalasr
Copy link
Member

chalasr commented May 9, 2025

I don't see much need for accessing the problematic uid either, thanks for proposing.

@chalasr chalasr closed this May 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature ❄️ Feature Freeze Important Pull Requests to finish before the next Symfony "feature freeze" Status: Needs Review Uid
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants