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

[spiral/filters] Add error handling when performing casting #1016

Merged
merged 4 commits into from
Nov 22, 2023

Conversation

msmakouz
Copy link
Member

Q A
Bugfix? ✔️
Breaks BC?
New feature? ✔️

What was changed

Added exception handling for errors occurring during value casting using Spiral\Filters\Model\Mapper\EnumCaster, Spiral\Filters\Model\Mapper\UuidCaster, and Spiral\Filters\Model\Mapper\DefaultCaster. Now, in the event of errors, a Spiral\Filters\Exception\SetterException will be thrown.

Introduced the Spiral\Filters\Attribute\CastingErrorMessage attribute, allowing the specification of an error message for enhanced error handling.

use Ramsey\Uuid\UuidInterface;
use Spiral\Filters\Attribute\Input\Post;
use Spiral\Filters\Attribute\CastingErrorMessage;
use Spiral\Filters\Model\Filter;

final class CreateUser extends Filter
{
    #[Post]
    public string $name;

    #[Post]
    #[CastingErrorMessage('Invalid UUID')]
    public UuidInterface $groupUuid;
}

Copy link

codecov bot commented Nov 16, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (6714d80) 89.17% compared to head (a9d1024) 89.21%.
Report is 6 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1016      +/-   ##
============================================
+ Coverage     89.17%   89.21%   +0.04%     
- Complexity     6124     6146      +22     
============================================
  Files           808      810       +2     
  Lines         17307    17364      +57     
============================================
+ Hits          15433    15492      +59     
+ Misses         1874     1872       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


public function __construct(
protected ?string $message = null,
?callable $callback = null
Copy link
Member

Choose a reason for hiding this comment

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

Let's add psalm annotation for closure?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added

@butschster
Copy link
Member

It works as expected!

@butschster butschster requested a review from wolfy-j November 21, 2023 14:23
@butschster butschster merged commit e09951d into master Nov 22, 2023
9 checks passed
@butschster butschster deleted the feature/filter branch November 22, 2023 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants