Open tom-schmitz opened 4 years ago
Hi @LukeTowers just a mention in case GitHub didn't send a notification
@tom-schmitz please update to the newest version of October available and confirm that the bug still exists
@LukeTowers, I've just update to the latest version of October (468). However the error is still present. Error occurs when pressing the sync button or using the command.
[Screenshot]
But I noticed one thing when I first create a new feed the sync works all post all listed. So then I deleted all of them via the database, and press the sync button once again in the backend I still get the same error and no new items show up in the list. But when I then refresh the page all of the posts are listed.
Do you have any other clue to what could cause this error to occur?
@tom-schmitz hmm, how very odd indeed. I can't think of why false
would be making it to that part of the code, are you able to send me a copy of your project with the database included so that I can test it locally? I can't reproduce this issue on any of my other environments.
@LukeTowers unfortunately I'm not able to share the project files or database. When I have some more time I will do some more debugging myself, if I find anything I will let you know. If in the meanwhile you find anything that could solve this, please do let me know.
@tom-schmitz are you using any other plugins? Does this behaviour persist if you remove all other plugins?
@LukeTowers I managed to look into the issue some more, and I think I found the issue.
After some debugging I noticed that the issue starts at plugins/luketowers/easyfacebookfeed/controllers/Feeds.php 43
ending at modules/backend/classes/Controller.php 526
where setContent()
gets called from here it calls a morphToJson()
this is where the error starts (vendor/laravel/framework/src/Illuminate/Http/Response.php 79
) the json_encode()
returns a false
. From here I called json_last_error ()
which returned:
JSON_ERROR_UTF8 | Malformed UTF-8 characters, possibly incorrectly encoded
So as a temporarily solution I add / changed the following in the Response.php (Solution from https://stackoverflow.com/questions/10199017/how-to-solve-json-error-utf8-error-in-php-json-decode#answer-26760943)
/**
* Morph the given content into JSON.
*
* @param mixed $content
* @return string
*/
protected function morphToJson($content)
{
if ($content instanceof Jsonable) {
return $content->toJson();
} elseif ($content instanceof Arrayable) {
return json_encode($content->toArray());
}
- return json_encode($content);
+ return $this->safe_json_encode($content);
}
+ protected function safe_json_encode($value, $options = 0, $depth = 512, $utfErrorFlag = false) {
+ $encoded = json_encode($value, $options, $depth);
+ switch (json_last_error()) {
+ case JSON_ERROR_NONE:
+ return $encoded;
+ case JSON_ERROR_DEPTH:
+ return 'Maximum stack depth exceeded'; // or trigger_error() or throw new Exception()
+ case JSON_ERROR_STATE_MISMATCH:
+ return 'Underflow or the modes mismatch'; // or trigger_error() or throw new Exception()
+ case JSON_ERROR_CTRL_CHAR:
+ return 'Unexpected control character found';
+ case JSON_ERROR_SYNTAX:
+ return 'Syntax error, malformed JSON'; // or trigger_error() or throw new Exception()
+ case JSON_ERROR_UTF8:
+ $clean = $this->utf8ize($value);
+ if ($utfErrorFlag) {
+ return 'UTF8 encoding error'; // or trigger_error() or throw new Exception()
+ }
+ return $this->safe_json_encode($clean, $options, $depth, true);
+ default:
+ return 'Unknown error'; // or trigger_error() or throw new Exception()
+
+ }
+ }
+
+ protected function utf8ize($mixed) {
+ if (is_array($mixed)) {
+ foreach ($mixed as $key => $value) {
+ $mixed[$key] = $this->utf8ize($value);
+ }
+ } else if (is_string ($mixed)) {
+ return utf8_encode($mixed);
+ }
+ return $mixed;
+ }
Perhaps you could come up with a way to catch the UTF-8 issue at the plugin level? Cause with the current temporarily solution, the issue returns when running a October update.
@tom-schmitz could you post the JSON / state that's causing the morphToJSON to fail?
Subject: Possible sync bug
October build: 458 Easy Facebook Feed: 1.10.0 PHP: 7.3
Error while syncing feed both manually (backend button) and via command line (or October schedule).
Thanks for your time.
Stack trance: