Skip to content

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

Merged
merged 2 commits into from
Aug 4, 2017
Merged

JsonProducer should check for errors #47

merged 2 commits into from
Aug 4, 2017

Conversation

prolic
Copy link
Owner

@prolic prolic commented Jul 7, 2017

resolves #46

@prolic prolic self-assigned this Jul 7, 2017
@coveralls
Copy link

coveralls commented Jul 7, 2017

Coverage Status

Coverage increased (+1.9%) to 92.888% when pulling 484d4a1 on json_encode into bc002f4 on master.

@prolic
Copy link
Owner Author

prolic commented Jul 7, 2017

@fritz-gerneth can you review please?

@coveralls
Copy link

coveralls commented Jul 7, 2017

Coverage Status

Coverage increased (+1.8%) to 92.809% when pulling 7e26fa7 on json_encode into bc002f4 on master.

$this->exchange->publish(json_encode($message), $routingKey, $flags, $attributes);
try {
$message = json_encode($message);
} catch (\Throwable $e) {

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. )

Copy link
Owner Author

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()

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.

Copy link
Owner Author

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.

Choose a reason for hiding this comment

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

Good to know then :)

@prolic prolic merged commit 2605593 into master Aug 4, 2017
@prolic prolic deleted the json_encode branch August 4, 2017 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JsonProducer should check for errors
3 participants