{"record":{"id":"0fee88cd98d31f8d","repo":"micro/go-micro","slug":"failed-to-parse-submit-response-w","errorCode":null,"errorMessage":"failed to parse submit response: %w","messagePattern":"failed to parse submit response: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ai/atlascloud/atlascloud.go","lineNumber":976,"sourceCode":"\t\treturn nil, fmt.Errorf(\"API request failed: %w\", err)\n\t}\n\tdefer httpResp.Body.Close()\n\n\trespBody, _ := io.ReadAll(httpResp.Body)\n\tif httpResp.StatusCode != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"API error (%s): %s\", httpResp.Status, string(respBody))\n\t}\n\n\tvar submitResp struct {\n\t\tCode int    `json:\"code\"`\n\t\tMsg  string `json:\"message\"`\n\t\tData struct {\n\t\t\tID     string `json:\"id\"`\n\t\t\tStatus string `json:\"status\"`\n\t\t} `json:\"data\"`\n\t}\n\tif err := json.Unmarshal(respBody, &submitResp); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to parse submit response: %w\", err)\n\t}\n\tif submitResp.Code != 200 {\n\t\treturn nil, fmt.Errorf(\"API error: %s\", submitResp.Msg)\n\t}\n\n\tpredictionID := submitResp.Data.ID\n\tpollURL := strings.TrimRight(p.opts.BaseURL, \"/\") + \"/api/v1/model/prediction/\" + predictionID\n\n\tticker := time.NewTicker(2 * time.Second)\n\tdefer ticker.Stop()\n\n\tfor {\n\t\tselect {\n\t\tcase <-ctx.Done():\n\t\t\treturn nil, ctx.Err()\n\t\tcase <-ticker.C:\n\t\t\tresult, err := p.pollPrediction(ctx, pollURL)\n\t\t\tif err != nil {","sourceCodeStart":958,"sourceCodeEnd":994,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/ai/atlascloud/atlascloud.go#L958-L994","documentation":"GenerateImage wraps the json.Unmarshal error when decoding the 200 submit response into {code, message, data:{id,status}}. A 200 body that is not this envelope (empty body, HTML, changed field types) triggers it, meaning the API succeeded at HTTP level but the payload is unreadable.","triggerScenarios":"json.Unmarshal(respBody, &submitResp) fails after a 200 from the image endpoint: empty/truncated body, HTML from a proxy, or fields whose types changed (e.g. code returned as string).","commonSituations":"Provider API version drift changing the response envelope; gateway/WAF injecting content into 200 responses; response body truncated by network issues (io.ReadAll error ignored).","solutions":["Log string(respBody) alongside the error to compare the actual payload to the expected envelope.","Check Content-Type of the 200 response for text/html from an intermediary.","Update the provider struct if AtlasCloud changed its response schema; capture io.ReadAll errors to detect truncation.","Pin the API version in BaseURL if the provider offers versioned endpoints."],"exampleFix":"if err := json.Unmarshal(respBody, &submitResp); err != nil {\n    return nil, fmt.Errorf(\"failed to parse submit response: %w (body: %.200s)\", err, string(respBody))\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"func looksLikeSubmitEnvelope(body []byte) bool {\n    var probe struct {\n        Code int             `json:\"code\"`\n        Data json.RawMessage `json:\"data\"`\n    }\n    return json.Unmarshal(body, &probe) == nil && probe.Data != nil\n}","tryCatchPattern":"img, err := provider.GenerateImage(ctx, req)\nif err != nil && strings.Contains(err.Error(), \"failed to parse submit response\") {\n    log.Printf(\"AtlasCloud submit payload unreadable — dump body and check for schema drift: %v\", err)\n    return err\n}","preventionTips":["Capture and log the raw body on parse failure to diagnose schema changes fast.","Pin API versions where possible and watch AtlasCloud changelogs.","Verify intermediaries (WAF/proxy) don't rewrite 200 response bodies.","Read io.ReadAll's error instead of discarding it to catch truncated bodies."],"tags":["json","schema-mismatch","go","atlascloud"],"backgroundTag":"response-schema-validation-failed","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}