Return a default user record if json is broken#17494
Merged
Conversation
It's possible that json_decode returns null. Mostly the json is broken. AddMissingDefaultValues expects an array. Pass null will fail. Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
ChristophWurst
approved these changes
Dec 13, 2019
Member
ChristophWurst
left a comment
There was a problem hiding this comment.
👍 for @kesselb's fix.
Added some logging so this doesn't happen unnoticed.
c9511c6 to
b97d90e
Compare
kesselb
commented
Dec 13, 2019
| $userDataArray = json_decode($result[0]['data'], true); | ||
| $jsonError = json_last_error(); | ||
| if ($userDataArray === null || $jsonError !== JSON_ERROR_NONE) { | ||
| $this->logger->critical("User data of $uid contained invalid JSON (error $jsonError), hence falling back to a default user record"); |
Contributor
Author
There was a problem hiding this comment.
json_last_error_msg() would log a readable error message. But the numeric code is also fine for me.
Member
There was a problem hiding this comment.
Didn't know about that!
For the sake of finally getting this in for 18 I'll leave it as is :)
kesselb
commented
Dec 13, 2019
Contributor
Author
|
CI looks good to me. |
blizzz
approved these changes
Dec 13, 2019
Member
|
/backport to stable17 |
Member
|
/backport to stable16 |
|
The backport to stable17 failed. Please do this backport manually. |
|
The backport to stable16 failed. Please do this backport manually. |
Contributor
Author
|
18 is fine for me. We can backport it later if necessary. |
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #16340
It's possible that json_decode returns null. Mostly the json is broken.
AddMissingDefaultValues expects an array. Pass null will fail.
How to reproduce: Modify the json in oc_accounts.
Not sure if we need some repair job to kill those broken records. Looks like an edge case to me.