-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] Improve CircularReference detection message #23322
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
Conversation
@@ -195,7 +195,7 @@ protected function handleCircularReference($object) | |||
return call_user_func($this->circularReferenceHandler, $object); | |||
} | |||
|
|||
throw new CircularReferenceException(sprintf('A circular reference has been detected (configured limit: %d).', $this->circularReferenceLimit)); | |||
throw new CircularReferenceException(sprintf('A circular reference has been detected (configured limit: %d) on %s.', $this->circularReferenceLimit, get_class($object))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May I suggest A circular reference has been detected when serializing the object of class "App\Domain\User" identified by "00000000462ff471000000005e39f75b" (configured limit: 1).
?
(Use spl_object_hash
to get the id).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated 👍
fe4161a
to
dab69c3
Compare
@@ -195,7 +195,7 @@ protected function handleCircularReference($object) | |||
return call_user_func($this->circularReferenceHandler, $object); | |||
} | |||
|
|||
throw new CircularReferenceException(sprintf('A circular reference has been detected (configured limit: %d).', $this->circularReferenceLimit)); | |||
throw new CircularReferenceException(sprintf('A circular reference has been detected when serializing the object of class "%s" identified by "%s" (configured limit: %d)', get_class($object), spl_object_hash($object), $this->circularReferenceLimit)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does the hash provide any value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may help if we catch this exception and show spl_hash of each normalized objects to compare. Honestly I'm not convinced too. I will remove it.
We could merge this as minor on the lowest branch where it applies, no need to consider it a new feature IMHO. |
dab69c3
to
3a529e3
Compare
Updated to lowest branch possible (2.7) |
Thank you @ScullWM. |
… (ScullWM) This PR was merged into the 2.7 branch. Discussion ---------- [Serializer] Improve CircularReference detection message | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | License | MIT Hi, I've get a CircularReferenceException error while serializing object with nested levels. Detect a CircularReference is great, but having more information about the object that generate this exception is better. I simply suggest to add a `get_class` of the current object in the error message. Before: `A circular reference has been detected (configured limit: 1).` After (edit) `A circular reference has been detected when serializing the object of class "App\Domain\User" (configured limit: 1).` Commits ------- 3a529e3 Improve CircularReferenceException message
Hi,
I've get a CircularReferenceException error while serializing object with nested levels. Detect a CircularReference is great, but having more information about the object that generate this exception is better.
I simply suggest to add a
get_class
of the current object in the error message.Before:
A circular reference has been detected (configured limit: 1).
After (edit)
A circular reference has been detected when serializing the object of class "App\Domain\User" (configured limit: 1).