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

::from(...) Wrong error message when there's attribute name issue in a nested class #809

Closed
ropi-bc opened this issue Jul 3, 2024 · 2 comments

Comments

@ropi-bc
Copy link

ropi-bc commented Jul 3, 2024

✏️ Describe the bug
In the case of trying to use laravel-data objects to make handling external API responses easier, there'll probably be a lot of nested DTO objects that need to be instantiated when using OuterClass::from($response->json()). If there's a typo in one of the nested classes, or I fail to add the proper #[MapInputName(...)] attribute, there'll be an exception somewhere inside the pipeline along the lines of InnerClass::__construct(): expects 2 arguments, 1 given correct_arg, missing arg_with_tpyo.

The issue is, that this error message never makes it to me, the developer. The error message I get is something like TypeError: App\DTOs\OuterObject::__construct(): Argument #1 ($innerObjects) must be of type Illuminate\Support\Collection, array given instead, which masquerades the root issue completely. After some small investigation, I found that this silent failure error is happening on this line. The CannotCreateData exception has the correct error message, but instead of rethrowing the exception, or logging the error, it just ignores it completely.

↪️ To Reproduce
See test in this example project.

✅ Expected behavior
I expect to see the message Could not create InnerClass: the constructor requires 2 parameters, 1 given. Parameters given: arg2. Parameters missing: arg1.

🖥️ Versions

Laravel: 11.9
Laravel Data: 4.7
PHP: 8.3

@rubenvanassche
Copy link
Member

Should be fixed in the next release with 95b7c8a

@ropi-bc
Copy link
Author

ropi-bc commented Nov 21, 2024

Thank you, this is great news!

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

No branches or pull requests

2 participants