8000 [JsonResponse] Silent only JSON errors by GromNaN · Pull Request #11418 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[JsonResponse] Silent only JSON errors #11418

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

Closed
wants to merge 4 commits into from

Conversation

GromNaN
Copy link
Member
@GromNaN GromNaN commented Jul 18, 2014
Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? maybe
Fixed tickets #11415
License MIT
Doc PR n/a

$this->data = @json_encode($data, $this->encodingOptions);
$errorHandler = null;
$errorHandler = set_error_handler(function () use (&$errorHandler) {
if (JSON_ERROR_NONE !== json_last_error()) {
Copy link
Member

Choose a reason for hiding this comment

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

are you sure this will cover the case properly ? If the error happens early in the error handling, the json_last_error might be related to a previous json operation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, that's the tricky part.

I can run json_encode(null) before to clear json_last_error().
But it's still possible to execute json_encode or json_decode inside a JsonSerializable object.

Copy link
Member Author

Choose a reason for hiding this comment

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

The most reliable way to know if the error has been triggered by this call to json_encode is to check the $errfile and $errline.

@fabpot
Copy link
Member
fabpot commented Sep 15, 2014

@GromNaN What's the status of this PR? Is it ready to be merged?

@GromNaN GromNaN force-pushed the jsonserializable-error branch from e5f2d42 to a4a8535 Compare September 15, 2014 20:53
@GromNaN
Copy link
Member Author
GromNaN commented Sep 15, 2014

That's very hard to test and to catch all cases.
I've rebased the branch, but I'm not sure if it fixes the issue perfectly.

@fabpot
Copy link
Member
fabpot commented Sep 16, 2014

@GromNaN Thanks for your feedback. As your PR is an improvement over the current situation, I think it's safe to merge it as is. Perfection can be achieved later on... is possible at all.

👍

@@ -201,4 +201,32 @@ public function testSetContent()
{
JsonResponse::create("\xB1\x31");
}

/**
* @expectedException Exception
Copy link
Member Author

Choose a reason for hiding this comment

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

The warning is converted to an exception by PHPUnit.

@fabpot
Copy link
Member
fabpot commented Sep 22, 2014

Thank you @GromNaN.

fabpot added a commit that referenced this pull request Sep 22, 2014
This PR was submitted for the master branch but it was merged into the 2.5 branch instead (closes #11418).

Discussion
----------

[JsonResponse] Silent only JSON errors

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | maybe
| Fixed tickets | #11415
| License       | MIT
| Doc PR        | n/a

Commits
-------

6d6a3af Clear json_last_error
ef91f71 Fix JsonSerializable namespace
d952f90 Catch exceptions to restore the error handler
ddf95c7 [HttpFoundation] Silent only JSON errors
@fabpot fabpot closed this Sep 22, 2014
fabpot added a commit that referenced this pull request Jul 1, 2015
This PR was merged into the 2.6 branch.

Discussion
----------

[2.6] Towards 100% HHVM compat

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #9917, #11418
| License       | MIT
| Doc PR        | -

Failing components:
- [x] HttpFoundation
- [x] HttpKernel
- [x] VarDumper

Related HHVM issues:
- facebook/hhvm#5563

Commits
-------

8a78255 [2.6] Towards 100% HHVM compat
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.

3 participants
0