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

Skip to content

[Serializer] Throw NotNormalizableException instead of InvalidArgumentException in ArrayDenormalizer #46652

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

NorthBlue333
Copy link

@NorthBlue333 NorthBlue333 commented Jun 12, 2022

Q A
Branch? 6.2
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #46649
License MIT
Doc PR -

As stated in #46649, I think the ArrayDenormalizer should throw a NotNormalizableValueException in case of not-array $data.

I have also added NotNormalizableValueException to DenormalizerInterface's denormalize method PHPDoc.

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 6.2 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@NorthBlue333 NorthBlue333 force-pushed the fix/array_denormalizer_exceptions_ticket_46649 branch from c94f365 to d65a686 Compare June 12, 2022 17:19
Copy link
Contributor

@mtarld mtarld left a comment

Choose a reason for hiding this comment

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

LGTM!

Btw, to me, it's a feature, therefore it should target the 6.2 branch 🙂

@NorthBlue333 NorthBlue333 force-pushed the fix/array_denormalizer_exceptions_ticket_46649 branch from d65a686 to a9ca866 Compare June 12, 2022 18:22
@NorthBlue333 NorthBlue333 changed the base branch from 6.1 to 6.2 June 12, 2022 18:22
@NorthBlue333
Copy link
Author

Done, the target branch is now 6.2.
Thanks for the feedback !

@NorthBlue333 NorthBlue333 force-pushed the fix/array_denormalizer_exceptions_ticket_46649 branch from a9ca866 to 7ee6dca Compare June 12, 2022 18:24
@mtarld
Copy link
Contributor

mtarld commented Jun 12, 2022

You're welcome! Don't forget to update the changelog as well

@NorthBlue333 NorthBlue333 force-pushed the fix/array_denormalizer_exceptions_ticket_46649 branch from 7ee6dca to d549f55 Compare June 12, 2022 19:50
@lyrixx
Copy link
Member

lyrixx commented Jun 13, 2022

I also noted that. But I don't know if it's a BC or not

Copy link
Member

@chalasr chalasr 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

@NorthBlue333
Copy link
Author

@lyrixx Same, I was not sure. But after some thinking, I think it is a BC because it will break try/catch blocks based on InvalidArgumentException.

@ogizanagi
Copy link
Contributor

@lyrixx Same, I was not sure. But after some thinking, I think it is a BC because it will break try/catch blocks based on InvalidArgumentException.

It replaces a logic exception (which are not meant to be caught, meant to be fixed in code) with a runtime exception, so no BC break to me.

if (!str_ends_with($type, '[]')) {
throw new InvalidArgumentException('Unsupported class: '.$type);
}

if (!\is_array($data)) {
Copy link
Member

Choose a reason for hiding this comment

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

Why inverting the order with the check on the type? Calling is_array() is cheaper than calling str_ends_with(), so it should be done first (especially because this method is ok the hot path and can be called hundreds of times).

Copy link
Member

Choose a reason for hiding this comment

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

@NorthBlue333 Can you answer this question please?

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed, IHMO, there is no need to change the order of checks there.

Copy link
Author

Choose a reason for hiding this comment

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

Hi, sorry did not have much time for those PRs. I will take a look during the end of the week.

@nicolas-grekas nicolas-grekas modified the milestones: 6.1, 6.2 Jun 19, 2022
if (!str_ends_with($type, '[]')) {
throw new InvalidArgumentException('Unsupported class: '.$type);
}

if (!\is_array($data)) {
Copy link
Member

Choose a reason for hiding this comment

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

@NorthBlue333 Can you answer this question please?

@NorthBlue333
Copy link
Author

While wanting to rebase with 6.2, I realized that #47169 has been merged in august. We can close this PR.

@chalasr chalasr closed this Oct 8, 2022
@chalasr
Copy link
Member

chalasr commented Oct 8, 2022

Thanks @NorthBlue333

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.

[Serializer] Incorrect exception thrown by ArrayDenormalizer
10 participants