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

listen to other exceptions #748

Merged
merged 2 commits into from
Dec 26, 2022
Merged

listen to other exceptions #748

merged 2 commits into from
Dec 26, 2022

Conversation

garak
Copy link
Collaborator

@garak garak commented Dec 8, 2022

Fix #747

@garak garak requested a review from alexpozzi December 8, 2022 16:22
Comment on lines 26 to 44
private static function isInternalException(UnexpectedValueException $exception): bool
{
$messages = [
'/^Cannot filter by\: \[.+\] this field is not in allow list$/',
'/^Cannot sort by\: \[.+\] this field is not in allow list\.$/',
'/^Cannot sort with array parameter$/',
'/^ODM query must be a FIND type query$/',
'/^There is no component aliased by \[.+\] in the given Query$/',
'/^There is no component field \[.+\] in the given Query$/',
'/^There is no such field \[.+\] in the given Query component, aliased by \[.+\]$/',
];
foreach ($messages as $regex) {
if (preg_match($regex, $exception->getMessage()) > 0) {
return true;
}
}

return false;
}
Copy link
Member

Choose a reason for hiding this comment

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

I'm usually not so fond of matching an exception by its message, especially if we control those exceptions.
Can't we create instead a custom exception (that's extending the UnexpectedValueException) and catch that instead of matching the messages?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree and I already opened an issue for that KnpLabs/knp-components#317
The problem is that we can only add the internal exception in a minor release of knp-components (e.g. 4.1.0) and so the fix in this bundle would stay for the users still using version 4.0.
My idea about the roadmap is:

  1. add the internal exception in the library, release a minor version of the library
  2. add support in the bundle for both (new internal exception and ugly old message-based exceptions), release a patch version of the bundle
  3. release a new minor version of the bundle, requiring library ^4.1 and removing the ugly old message-based exceptions

Copy link
Member

@alexpozzi alexpozzi Dec 9, 2022

Choose a reason for hiding this comment

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

Great! Sorry, I missed that issue.

Thank you!

@garak garak merged commit 92d676e into master Dec 26, 2022
@garak garak deleted the fix-exception branch January 1, 2023 16:46
@garak garak mentioned this pull request Jan 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exception in main library not converted
2 participants