-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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
Conversation
If we suddenly start to throw a different exception, wouldn't this break existing code that catches the "old" exception? |
Hi @derrabus ,
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. |
Yes, it is not released yet |
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. |
Specifically, I want to unify what exceptions are thrown form uid-classes. What I mean is following:
I want to unify it all so that whether you call Benefit is that |
I am not in favor of this change. If one wants to only care for one exception than for either |
One can not distinguish between 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. |
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 |
InvalidUuidException
and InvalidUlidException
Hi guys, I would like to move on if you don't mind |
I'm AFK until next week, I'll come back here ASAP. |
Sure, have a nice time Just want to make sure this doesn't get off to 7.3 release |
It's a small change, I think it mustn't need much work |
@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? |
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.
Works for me but let's keep only InvalidArgumentException, no need for InvalidUidException either.
|
@nicolas-grekas , hi again. Sorry for long waiting. So about this, it's more easily grasped by short name |
@nicolas-grekas , I'd rather keep |
My concern is about keeping both InvalidArgumentException and InvalidUidException : I had a look at where each is thrown and I'm not sure the difference makes sense. |
I agree with Nicolas. Right now we only throw those exception when UIDs are invalid thus both exceptions carry the same semantics. |
As far as I know, there are some other places where |
Yes, and my point is that throwing a different type of exception doesn't make sense to me (InvalidArgumentException vs InvalidUidException) |
Try to look at it from the client code perspective
|
You're missing the point I'm making. Let's forget about the name, that's not what I'm talking about. |
Sorry, then I didn't get your point |
Let's say we keep two types as currently proposed in this PR: InvalidArgumentException and InvalidUidException. |
We could've kept |
@rela589n it would be super helpful if you could open the code to understand why I'm having this opinion about the type hierarchy. |
Usages of
$uuid = $this->uid;
$time = BinaryUtil::hexToNumericString('0'.substr($uuid, 0, 8).substr($uuid, 9, 4).substr($uuid, 15, 3));
if ('-' === $time[0]) {
throw new InvalidArgumentException('Cannot convert UUID to v7: its timestamp is before the Unix epoch.');
}
if (null === $mtime = $time) {
$time = microtime(false);
$time = substr($time, 11).substr($time, 2, 3);
} elseif (0 > $time = $time->format('Uv')) {
throw new InvalidArgumentException('The timestamp must be positive.');
}
if (null === $mtime = $time) {
$time = microtime(false);
$time = substr($time, 11).substr($time, 2, 3);
} elseif (0 > $time = $time->format('Uv')) {
throw new InvalidArgumentException('The timestamp must be positive.');
}
if (-self::TIME_OFFSET_INT > $time = (int) $time->format('Uu0')) {
throw new InvalidArgumentException('The given UUID date cannot be earlier than 1582-10-15.');
} So therefore, all these usages are related to uuid generation, which is different from uuid reconstruction. Besides that, as other components define There are two kinds of this exception - one related to Uuid intended to be created from the value, and the other's related to generating Uuid. |
@nicolas-grekas , please let me know if this makes sense to you |
AFAIK the rare cases a component contains both an Exemples: Mailer
DependencyInjection
OptionsResolver
etc etc.. So.. imho any class extending |
I submitted #60530 instead. It doesn't make sense to me to have two kind of exceptions for that. About the name, I already explained the rationale to go with InvalidArgumentException: your arguments apply not only to Uid but to all other components. This means for consistency we'd want to change the name in all components. That's not going to happen as the migration cost would be too high compared to the alleged benefits. Thanks for submitting and for the discussion! |
…umentException (nicolas-grekas) This PR was merged into the 7.3 branch. Discussion ---------- [Uid] Remove InvalidU*idException in favor of InvalidArgumentException | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | Fix #60328 | License | MIT As discussed in #60328 Commits ------- 9fbc6a4 [Uid] Remove InvalidU*idException in favor of InvalidArgumentException
@smnandre , class inherently represents the type
@nicolas-grekas , probably you misunderstood me, since as I've said in the previous message insofar as other components define InvalidArgumentException, it's worth having it here as well. I have no intention to make drastic changes in exception usage. I just said that it's good to have dedicated |
This PR unifies
InvalidUuidException
andInvalidUlidException
, 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.