{"record":{"id":"a9f5eda4905e3c22","repo":"AlistGo/alist","slug":"failed-to-parse-response-v","errorCode":null,"errorMessage":"failed to parse response: %v","messagePattern":"failed to parse response: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/mediafire/util.go","lineNumber":440,"sourceCode":"\n\tbody, err := io.ReadAll(res.Body)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to read response body: %v\", err)\n\t}\n\n\t//fmt.Printf(\"MediaFire resumable upload response (status %d): %s\\n\", res.StatusCode, string(body))\n\n\tvar uploadResp struct {\n\t\tResponse struct {\n\t\t\tDoupload struct {\n\t\t\t\tKey string `json:\"key\"`\n\t\t\t} `json:\"doupload\"`\n\t\t\tResult string `json:\"result\"`\n\t\t} `json:\"response\"`\n\t}\n\n\tif err := json.Unmarshal(body, &uploadResp); err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to parse response: %v\", err)\n\t}\n\n\tif res.StatusCode != 200 {\n\t\treturn \"\", fmt.Errorf(\"resumable upload failed with status %d\", res.StatusCode)\n\t}\n\n\treturn uploadResp.Response.Doupload.Key, nil\n}\n\nfunc (d *Mediafire) uploadUnits(ctx context.Context, file *os.File, checkResp *MediafireCheckResponse, filename, fileHash, folderKey string, up driver.UpdateProgress) (string, error) {\n\tunitSize, _ := strconv.ParseInt(checkResp.Response.ResumableUpload.UnitSize, 10, 64)\n\tnumUnits, _ := strconv.Atoi(checkResp.Response.ResumableUpload.NumberOfUnits)\n\tuploadKey := checkResp.Response.ResumableUpload.UploadKey\n\n\tstringWords := checkResp.Response.ResumableUpload.Bitmap.Words\n\tintWords := make([]int, len(stringWords))\n\tfor i, word := range stringWords {\n\t\tintWords[i], _ = strconv.Atoi(word)","sourceCodeStart":422,"sourceCodeEnd":458,"githubUrl":"https://github.com/AlistGo/alist/blob/843d9dc8149126976b2625911e45a4d3ffd6f2f5/drivers/mediafire/util.go#L422-L458","documentation":"json.Unmarshal failed on the body returned by /upload/resumable.php. The endpoint returned something that is not the expected JSON envelope — commonly an HTML error page, an empty body, or a plain-text gateway error. Because the driver reads the whole body first, the raw payload is available but (as evidenced by commented-out debug prints) is not included in the error, making diagnosis hard.","triggerScenarios":"MediaFire or an intermediary (CDN/WAF) returning HTML for a 502/503; Content-Type mismatches when the API changes; empty body on early connection close; XML or error format returned because response_format was not honored.","commonSituations":"Transient gateway errors from mediafire.com; API contract changes after MediaFire updates; rate limiting responses that are HTML interstitials; response_format=json omitted or overridden by a redirect.","solutions":["Log/include the body snippet and status code in the error so the actual payload is visible","Retry once after backoff — gateway HTML pages are almost always transient","Confirm the request includes response_format=json and follows redirects properly","If persistent, dump the body and compare against the current MediaFire API docs for format changes"],"exampleFix":"// before\nif err := json.Unmarshal(body, &uploadResp); err != nil {\n    return \"\", fmt.Errorf(\"failed to parse response: %v\", err)\n}\n\n// after\nif err := json.Unmarshal(body, &uploadResp); err != nil {\n    return \"\", fmt.Errorf(\"failed to parse response: %v, status=%d, body=%.200s\", err, res.StatusCode, body)\n}","handlingStrategy":"retry","validationCode":"// Cheap content sniff before unmarshal\nif len(body) == 0 { return errors.New(\"empty response body\") }\nif bytes.HasPrefix(bytes.TrimSpace(body), []byte(\"<\")) {\n    return fmt.Errorf(\"non-JSON (HTML) response, status=%d\", res.StatusCode)\n}","typeGuard":null,"tryCatchPattern":"// Retry once on HTML/empty bodies (gateway blips), fail fast on real JSON errors\nif err := json.Unmarshal(body, &v); err != nil {\n    if isTransientBody(body) { return retryWithBackoff(...) }\n    return fmt.Errorf(\"parse failed: %v body=%.200s\", err, body)\n}","preventionTips":["Always include body snippet + status in parse errors","Keep response_format=json on every request","Sniff for HTML prefixes before unmarshal to classify gateway errors"],"tags":["mediafire","json","parsing","upload","go"],"backgroundTag":null,"analyzedSha":"843d9dc8149126976b2625911e45a4d3ffd6f2f5","analyzedAt":"2026-08-15T12:14:11.722Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}