-
-
Notifications
You must be signed in to change notification settings - Fork 17
JsonProducer should check for errors #47
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
@fritz-gerneth can you review please? |
$this->exchange->publish(json_encode($message), $routingKey, $flags, $attributes); | ||
try { | ||
$message = json_encode($message); | ||
} catch (\Throwable $e) { |
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.
To my knowledge json_encode
will never throw an exception (SO, PHP Doc Comment. )
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.
json_encode
does not throw an exception, but an object implementing JsonSerializable
can throw an exception in its jsonSerialize
method.
$producer = new JsonProducer($exchange->reveal()); | ||
|
||
$message = new class() implements \JsonSerializable { | ||
public function jsonSerialize() |
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.
As suggested by php PHP Doc's comments this will be catched and consumed by json_encode
. Not saying the test is wrong, just think they both get handled by the json_last_error
condition.
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.
No it won't, the exception in jsonSerialize
method is thrown instead. I tested this already.
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.
Good to know then :)
resolves #46