woocommerce / woocommerce-ios

WooCommerce iOS app
https://www.woocommerce.com/mobile
GNU General Public License v2.0
300 stars 110 forks source link

Media: Decoding errors with image upload failures #4633

Open rachelmcr opened 3 years ago

rachelmcr commented 3 years ago

Describe the bug

Looking at our analytics for image upload failures (product_image_upload_failed), there are two recurring decoding errors in the error_description for those failures.

This one occurs ~5-15 times/day:

Swift.DecodingError.keyNotFound(CodingKeys(stringValue: "ID", intValue: nil), Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "media", intValue: nil), _JSONKey(stringValue: "Index 0", intValue: 0)], debugDescription: "No value associated with key CodingKeys(stringValue: \"ID\", intValue: nil) (\"ID\").", underlyingError: nil))

This one is more rare, occurring ~1 time every couple days:

Swift.DecodingError.keyNotFound(CodingKeys(stringValue: "media", intValue: nil), Swift.DecodingError.Context(codingPath: [], debugDescription: "No value associated with key CodingKeys(stringValue: \"media\", intValue: nil) (\"media\").", underlyingError: nil))
rachelmcr commented 3 years ago

I found some recent examples of this first decoding error:

Swift.DecodingError.keyNotFound(CodingKeys(stringValue: "ID", intValue: nil), Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "media", intValue: nil), _JSONKey(stringValue: "Index 0", intValue: 0)], debugDescription: "No value associated with key CodingKeys(stringValue: \"ID\", intValue: nil) (\"ID\").", underlyingError: nil))

I haven't been able to reproduce it, but it looks like that error tends to occur just before failures caused by Dotcom Error: [json_syntax] Invalid response from the Jetpack site or Dotcom Request Failed. I'm guessing that what happens is some kind of communication issue with the site or a plugin conflict that causes the first upload attempt to return an incomplete media upload response, resulting in that decoding error.

I'm not sure if there's a straightforward solution here, since we need the media ID and other details to use the image in the app.

rachelmcr commented 1 year ago

The first decoding error came up for a user in 5609645-zen. In this case, their site's Jetpack connection is broken:

The Jetpack site is inaccessible or returned an error: transport error - HTTP status code was not 200 (404) [-32300]

Perhaps we could handle this better by checking the health of the Jetpack connection more proactively and focusing on guiding users to fix broken connections before they encounter more specific issues like this one.

jaclync commented 1 year ago

Another similar issue with the same WP.com error [json_syntax] Invalid response from the Jetpack site on the media request in 5616855-zd-woothemes Their site's Jetpack connection has some issues (We were unable to fetch the data from your Jetpack-powered site, the communication channel seems to be broken.) and the XML-RPC file can only be accessed once in a while.