Skip to content
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

Add Fully-Qualified class name in UnrecognizedField exception #10342

Merged
merged 1 commit into from
Dec 31, 2022

Conversation

Kern046
Copy link
Contributor

@Kern046 Kern046 commented Dec 26, 2022

Currently if we use a field that is not properly registered in our mapping, we end up with the following exception from the BasicEntityPersister:

Unrecognized field: {field}

As with a complete stack trace we may be able to dig enough to find the right mapping, it can take more time to find the concerned entity in a context with less informations, such as logs.

This PR adds the entity FQCN to the exception message to ease debugging in such cases, using the class metadata available in BasicEntityPersister::class property. We end up with:

Unrecognized field: {fqcn}::{field}

As I didn't encountered any tests for the existing UnrecognizedException class behavior, I didn't add some but I can if needed.

Copy link
Member

@greg0ire greg0ire left a comment

Choose a reason for hiding this comment

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

Great idea, I think I remember losing time over this a few years ago.

@Kern046 Kern046 force-pushed the evol/add-unrecognized-field-fqcn branch 2 times, most recently from cd6f352 to 47b3814 Compare December 27, 2022 00:19
greg0ire
greg0ire previously approved these changes Dec 27, 2022
Copy link
Member

@SenseException SenseException left a comment

Choose a reason for hiding this comment

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

As far as I can see were these the only occurrences of UnrecognizedField::byName() and this method is now unused. Exceptions' named constructors are for internal usage, but can be used elsewhere in userland. Should it be removed now or set as deprecated first?

@greg0ire
Copy link
Member

I'm OK with it being removed now.

@Kern046
Copy link
Contributor Author

Kern046 commented Dec 28, 2022

I'm OK with it being removed now.

I thought it would be a BC to remove it, some users may use this method. Maybe we should deprecate it instead ?

Copy link
Member

@derrabus derrabus left a comment

Choose a reason for hiding this comment

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

Sorry if I'm nit-picking too much here, but if the exception message is that important to you, I believe we should have a test that makes sure the exception message is as you expect it to be.

@derrabus
Copy link
Member

I thought it would be a BC to remove it, some users may use this method. Maybe we should deprecate it instead ?

This PR is filed as a bugfix, so I'd really vote against removing any methods. Yes, I believe we should deprecate the method, but we cannot introduce deprecations in a bugfix release either. So let's do that in a follow-up on 2.15.x.

@greg0ire
Copy link
Member

Regarding what is a BC and what is not : https://xkcd.com/1172/

I always fear I'm going to be too strict, only to find my fellow maintainers think otherwise. The BC is small, but this isn't just any library, so let's avoid unnecessary risks.

@Kern046
Copy link
Contributor Author

Kern046 commented Dec 30, 2022

Sorry if I'm nit-picking too much here, but if the exception message is that important to you, I believe we should have a test that makes sure the exception message is as you expect it to be.

Done :)

Regarding what is a BC and what is not : https://xkcd.com/1172/

I always fear I'm going to be too strict, only to find my fellow maintainers think otherwise. The BC is small, but this isn't just any library, so let's avoid unnecessary risks.

I added a deprecation notice with a link to the new method.

@Kern046 Kern046 force-pushed the evol/add-unrecognized-field-fqcn branch from 2de8a96 to afeec59 Compare December 31, 2022 12:04
@derrabus derrabus added this to the 2.14.1 milestone Dec 31, 2022
UPGRADE.md Outdated Show resolved Hide resolved
@Kern046 Kern046 force-pushed the evol/add-unrecognized-field-fqcn branch from afeec59 to c52faf9 Compare December 31, 2022 13:24
@derrabus derrabus merged commit 28e98b3 into doctrine:2.14.x Dec 31, 2022
derrabus added a commit to derrabus/orm that referenced this pull request Dec 31, 2022
* 2.14.x:
  Shorter deprecation message (doctrine#10357)
  Add Fully-Qualified class name in UnrecognizedField exception to ease debugging (doctrine#10342)
  Include parameter types in hydration cache key generation (doctrine#10355)
@Kern046 Kern046 deleted the evol/add-unrecognized-field-fqcn branch December 31, 2022 16:47
derrabus added a commit to derrabus/orm that referenced this pull request Dec 31, 2022
* 2.15.x:
  Shorter deprecation message (doctrine#10357)
  Add Fully-Qualified class name in UnrecognizedField exception to ease debugging (doctrine#10342)
  Include parameter types in hydration cache key generation (doctrine#10355)
  Allow doctrine/instantiator 2 (doctrine#10351)
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.

4 participants