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

thrown Exceptions are hidden when serializing complex objects with a handler #1168

Closed
Hikariii opened this issue Mar 11, 2020 · 2 comments
Closed

Comments

@Hikariii
Copy link
Contributor

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no

The try/finally block in the SerializationGraphNavigator making sure the context visitingStack is working correctly hides all Exceptions thrown in handlers when the context has started visiting a (nested) object but has not stopped visiting is.
This is the case in many situations where a handler (like the ArrayCollectionHandler) is used to serialize a more complex object (or object with objects).

Code hiding the exception is this one:
https://github.com/schmittjoh/serializer/blob/3.5.0/src/GraphNavigator/SerializationGraphNavigator.php#L196-L200
This is because finally is executed before the Exception is thrown and the stopVisiting() causes an other Exception to be thrown, hiding the first Exception.

Running stopVisiting() first is sometimes necessary

The commit that introduced this change makes it clear it is created for a specific situation where serializing NULL throws an exception: ffc0fee

The fact that this NotAcceptableException is needed is also mentioned in the UPGRADING guide: https://github.com/schmittjoh/serializer/blame/3.5.0/UPGRADING.md#L56-L57

Steps required to reproduce the problem

  1. Use a custom serializationHandler and serialize object data with it.
  2. In the handler start visiting a (nested) object, changing the visiting stack of the context.
  3. Throw an exception while the visiting stack is visiting this nested object.

Expected Result

  • The exception thrown while parsing the compex serialization structure is shown.

Actual Result

  • The exception thrown is an error about the visitingStack not working well:
RuntimeException('Context visitingStack not working well');
@goetas
Copy link
Collaborator

goetas commented Mar 12, 2020

Thanks for working on this. I think that is something we should fix.

@goetas
Copy link
Collaborator

goetas commented Mar 14, 2020

fixed in #1169

@goetas goetas closed this as completed Mar 14, 2020
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