Skip to content

Improve TypeCastingFailed message #561

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 5 commits into from
Mar 22, 2025

Conversation

nyamsprod
Copy link
Member

Resolve issue #560

We can not add the record field BUT we can add the object property so this should give enough information to help debugging the error.

@nyamsprod nyamsprod self-assigned this Mar 21, 2025
@nyamsprod nyamsprod force-pushed the feature/improve-typecastfailing-exception branch 2 times, most recently from 29e1d53 to e2c6621 Compare March 21, 2025 20:51
@nyamsprod nyamsprod force-pushed the feature/improve-typecastfailing-exception branch from e2c6621 to 780f578 Compare March 21, 2025 20:55
@nyamsprod
Copy link
Member Author

I updated the PR it is a bit more complex but the message should now be even clearer.

If the error comes from a setter method you will get something like this

Fatal error: Uncaught League\Csv\Serializer\TypeCastingFailed: Casting the method setReview() first argument foobar using the record field review failed; The null value can not be cast to a string; the property type is not nullable.

if an offset is used instead you will get the following:

Fatal error: Uncaught League\Csv\Serializer\TypeCastingFailed: Casting the property tags using the record field offset 5 failed; The null value can not be cast to a string; the property type is not nullable.

The current message is no longer changed but it is prefixed with a more detail information about the context around the type casting failure.

Copy link

@OliverBeckwith OliverBeckwith left a comment

Choose a reason for hiding this comment

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

Works great. These error messages are much more helpful now

@nyamsprod nyamsprod merged commit 9251c58 into master Mar 22, 2025
19 checks passed
@nyamsprod nyamsprod deleted the feature/improve-typecastfailing-exception branch March 22, 2025 19:49
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.

2 participants