Skip to content

[Uid] Add component-specific exception classes #60226

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

Merged
merged 1 commit into from
Apr 17, 2025

Conversation

nicolas-grekas
Copy link
Member

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

Generalization of #60154

/cc @rela589n

Copy link
Contributor

@rela589n rela589n left a comment

Choose a reason for hiding this comment

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

lovely ❤️

Comment on lines -44 to 48
$this->expectException(\InvalidArgumentException::class);
$this->expectException(InvalidUlidException::class);
$this->expectExceptionMessage('Invalid ULID: "this is not a ulid".');

Copy link
Contributor

Choose a reason for hiding this comment

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

@nicolas-grekas , really thank you, appreciate it a lot!

{
public function __construct(
public readonly int $type,
string $value,
Copy link
Contributor

Choose a reason for hiding this comment

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

do you think it'd be possible to make value accessible as well?

actually there'd been discussion regarding this in a previous MR, @fabpot prefers private property and getter

Copy link
Member Author

Choose a reason for hiding this comment

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

private property and getter

I saw that but I think this is still better :)

Comment on lines +14 to +16
class InvalidArgumentException extends \InvalidArgumentException
{
}
Copy link
Contributor

Choose a reason for hiding this comment

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

@nicolas-grekas , do you think it could contain value?

Copy link
Member

Choose a reason for hiding this comment

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

We generally don't include a value in our InvalidArgumentException exceptions. When such error happens for an error related to an object, this would mean that the exception retains a reference to that object (even if you never call the getter), which would have an impact on GC.

Copy link
Member Author

@nicolas-grekas nicolas-grekas Apr 16, 2025

Choose a reason for hiding this comment

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

What @stof wrote (and where the previous PR blocked IMHO)
So better not to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not a reference shall make the impact on garbage collection, unless it creates a circular reference.

Copy link
Member Author

Choose a reason for hiding this comment

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

Still, not something that makes sense to me.

Copy link
Member Author

@nicolas-grekas nicolas-grekas Apr 17, 2025

Choose a reason for hiding this comment

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

Sure, but it's not the responsibility of the exception to carry this as a standalone value. (the native InvalidArgumentException doesn't carry it if you want an example)

Copy link
Contributor

Choose a reason for hiding this comment

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

It is, and it must have the value inside

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm sorry you feel frustrated about the situation. We made a step in the direction you're aiming for but we don't do the last step for reasons I already shared. You'll have to parse the message for your use case...

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't feel any frustration about anything. I have a big lump of faith down inside of me believing that it is the way to go, and that it should be implemented.

Copy link
Contributor

Choose a reason for hiding this comment

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

@nicolas-grekas , I want you to receive this idea

@nicolas-grekas nicolas-grekas force-pushed the uid-exception-classes branch from abadae2 to 0c56a4b Compare April 16, 2025 13:56
@nicolas-grekas nicolas-grekas force-pushed the uid-exception-classes branch from 0c56a4b to e86ffe3 Compare April 16, 2025 14:01
@nicolas-grekas
Copy link
Member Author

Thank you @rela589n.

@nicolas-grekas nicolas-grekas merged commit 1d7c9ec into symfony:7.3 Apr 17, 2025
7 of 11 checks passed
@nicolas-grekas nicolas-grekas deleted the uid-exception-classes branch April 17, 2025 09:07
@fabpot fabpot mentioned this pull request May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants