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

Skip to content

[Uid] Unify InvalidUuidException and InvalidUlidException #60328

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

Open
wants to merge 2 commits into
base: 7.3
Choose a base branch
from

Conversation

rela589n
Copy link
Contributor

@rela589n rela589n commented May 2, 2025

Q A
Branch? 7.3
Bug fix? no
New feature? no
Deprecations? no
License MIT

This PR unifies InvalidUuidException and InvalidUlidException, created as the part of #60226 . InvalidUidException in itself gives enough context about its origin, and it's possible to determine whence the exception originated from by checking its getFile, or checking the trace.

Therefore, it's not necessary to make two exceptions if there can be only one.

@carsonbot carsonbot added this to the 7.3 milestone May 2, 2025
@rela589n rela589n changed the title [Uid] Unify InvalidUuidException and InvalidUlidException into single Inval… [Uid] Unify InvalidUuidException and InvalidUlidException May 2, 2025
@derrabus
Copy link
Member

derrabus commented May 2, 2025

If we suddenly start to throw a different exception, wouldn't this break existing code that catches the "old" exception?

@rela589n
Copy link
Contributor Author

rela589n commented May 2, 2025

Hi @derrabus ,

If we suddenly start to throw a different exception, wouldn't this break existing code that catches the "old" exception?

That's a great question.

No, it wouldn't break, since it has never been released.

That's why I'm opening this PR now, so that these two exceptions won't create backward compatibility promise starting from 7.3 and onward.

@OskarStark
Copy link
Contributor

Yes, it is not released yet

@nicolas-grekas
Copy link
Member

it's possible to determine whence the exception originated from by checking its getFile, or checking the trace.

This doesn't look like a good practice to me, so this sounds like a counter argument.

What benefit do you expect from this PR over the current situation?

Coincidentally, php-src is working on php/policies#17, that might give some food for thoughts on the topic.

@rela589n
Copy link
Contributor Author

rela589n commented May 5, 2025

Specifically, I want to unify what exceptions are thrown form uid-classes.

What I mean is following:

  • If you call Uuid::fromBase32(), currently you might get InvalidArgumentException, or InvalidUuidException;
  • If you call Ulid::fromBase32(), currently you might get InvalidArgumentException, or InvalidUlidException;

I want to unify it all so that whether you call Uuid::fromBase32(), or Ulid::fromBase32(), you'll get the same InvalidUidException that is related to AbstractUid rather than to any concrete implementation.

Benefit is that InvalidUidException is conceptually self-evident - it is thrown when creating uid.

@xabbuh
Copy link
Member

xabbuh commented May 5, 2025

I am not in favor of this change. If one wants to only care for one exception than for either InvalidUuidException or InvalidUlidException that's already possible by catching InvalidArgumentException instead. For anyone wanting to distinguish UUID and ULID having distinct exceptions is better.

@xabbuh xabbuh added the ❄️ Feature Freeze Important Pull Requests to finish before the next Symfony "feature freeze" label May 5, 2025
@rela589n
Copy link
Contributor Author

rela589n commented May 5, 2025

One can not distinguish between Uuid::fromBase32() and Ulid::fromBase32() (and fromBinary, fromBase58, fromRfc4122 as well) since these might fail due to the length check is in AbstractUid:

public static function fromBase32(string $uid): static
{
    if (26 !== \strlen($uid)) {
        throw new InvalidArgumentException($uid, 'Invalid base-32 uid provided.');
    }

    return static::fromString($uid);
}

So then it's not possible to distinguish anyway.

@rela589n
Copy link
Contributor Author

rela589n commented May 5, 2025

I am not in favor of this change.

As far as I remember, you were not in favor of the exceptions being introduced either.

Also, I remember @nicolas-grekas was for the idea to have one single InvalidUidException, while I stated that it's better to have them separate.

Now, I revised the code and see that it's better to have the unified interface so that make fromBinary, fromBase58, fromBase32, fromRfc4122 (actually any method that creates uid) throw it. It's totally clear from UI standpoint that InvalidUidException is thrown due to the creation

@OskarStark OskarStark changed the title [Uid] Unify InvalidUuidException and InvalidUlidException [Uid] Unify InvalidUuidException and InvalidUlidException May 5, 2025
@rela589n
Copy link
Contributor Author

rela589n commented May 5, 2025

Hi guys, I would like to move on if you don't mind

@nicolas-grekas
Copy link
Member

I'm AFK until next week, I'll come back here ASAP.

@rela589n
Copy link
Contributor Author

rela589n commented May 6, 2025

Sure, have a nice time

Just want to make sure this doesn't get off to 7.3 release

@rela589n
Copy link
Contributor Author

rela589n commented May 6, 2025

It's a small change, I think it mustn't need much work

@rela589n
Copy link
Contributor Author

rela589n commented May 9, 2025

@nicolas-grekas , @fabpot , just a quick check-in, since I don't want to introduce BC promise for 7.3, is it all right right?

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me but let's keep only InvalidArgumentException, no need for InvalidUidException either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
❄️ 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.

6 participants