Skip to content

Undefined array key 0 in RW::parseError() when results is an empty array #98

@petaak

Description

@petaak

RW::parseError() crashes with Undefined array key 0 when the API returns a successful response with an empty results array.

This happens because parseError() is called from RO::parseResponse() for every response that contains a success key (line 1264 of RO.php), regardless of whether the operation actually failed. Some API endpoints (e.g., automaticke-parovani) return a response like:

{
   "winstrom": {
      "@version": "1.0",
      "success": "true",
      "stats": {
         "created": "0",
         "updated": "0",
         "deleted": "0",
         "skipped": "0",
         "failed": "0"
      },
      "results": []
   }
}

In parseError(), the condition on line 170 of RW.php checks array_key_exists(0, $responseDecoded['results']). When $responseDecoded['results'] is empty, this returns false, and the code falls into the else branch (line 183) which immediately tries to access $responseDecoded['results'][0]['result'] - the very key that was just confirmed to not exist.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggood first issueGood for newcomersinvalidThis doesn't seem right

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions