{"record":{"id":"5dfc8df7fda6834e","repo":"Netflix/chaosmonkey","slug":"failed-to-parse-json-at-s","errorCode":null,"errorMessage":"failed to parse json at %s","messagePattern":"failed to parse json at (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"spinnaker/spinnaker.go","lineNumber":284,"sourceCode":"\t}()\n\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn \"\", nil, errors.Errorf(\"unexpected response code (%d) from %s\", resp.StatusCode, url)\n\t}\n\n\tbody, err := ioutil.ReadAll(resp.Body)\n\tif err != nil {\n\t\treturn \"\", nil, errors.Wrap(err, fmt.Sprintf(\"body read failed at %s\", url))\n\t}\n\n\tvar data struct {\n\t\tName      string\n\t\tInstances []struct{ Name string }\n\t}\n\n\terr = json.Unmarshal(body, &data)\n\tif err != nil {\n\t\treturn \"\", nil, errors.Wrapf(err, \"failed to parse json at %s\", url)\n\t}\n\n\tasg := D.ASGName(data.Name)\n\tinstances := make([]D.InstanceID, len(data.Instances))\n\tfor i, instance := range data.Instances {\n\t\tinstances[i] = D.InstanceID(instance.Name)\n\t}\n\n\treturn asg, instances, nil\n\n}\n\n// GetApp implements deploy.Deployment.GetApp\nfunc (s Spinnaker) GetApp(appName string) (*D.App, error) {\n\t// data arg is a map like {accountName: {clusterName: {regionName: {asgName: [instanceId]}}}}\n\tdata := make(D.AppMap)\n\tfor account, clusters := range s.clusters(appName) {\n\t\tcloudProvider, err := s.CloudProvider(account)","sourceCodeStart":266,"sourceCodeEnd":302,"githubUrl":"https://github.com/Netflix/chaosmonkey/blob/eaa28fb761c0ebe8644d1333e5d164e9cc3071e9/spinnaker/spinnaker.go#L266-L302","documentation":"Spinnaker.GetInstanceIDs throws this when json.Unmarshal fails to parse the response body into the expected {Name, Instances:[{Name}]} shape. The library wraps the unmarshal error with the URL, indicating the Spinnaker API returned something that is not the expected JSON structure.","triggerScenarios":"Calling GetInstanceIDs when the endpoint returns HTML (error/login page), an empty body, truncated JSON, or a schema that changed between Spinnaker versions (e.g. field renames or a wrapped payload).","commonSituations":"Auth redirect returning a login page with 200; Spinnaker API version upgrade changing the payload; proxy injecting an error page; wrong URL pattern hitting a different endpoint that returns different JSON.","solutions":["Log or print the raw body (temporarily) to see what the server actually returned.","Verify the Spinnaker version matches the API schema this library expects; pin or update the library accordingly.","Check whether an auth/login redirect is returning HTML instead of JSON.","Curl the URL and validate the JSON matches {\"name\":..., \"instances\":[{\"name\":...}]}.","Check for proxies or gateways mangling the response."],"exampleFix":"// before\nbody, _ := ioutil.ReadAll(resp.Body)\nvar data struct{ Name string; Instances []struct{ Name string } }\nerr = json.Unmarshal(body, &data)\n// after (diagnose first)\nif err != nil {\n    log.Printf(\"raw response from %s: %s\", url, string(body))\n}","handlingStrategy":"validation","validationCode":"// pre-validate that the endpoint speaks JSON\nreq, _ := http.NewRequest(\"GET\", accountsProbeURL, nil)\nreq.Header.Set(\"Accept\", \"application/json\")\nresp, err := httpClient.Do(req)\nif err != nil {\n    return err\n}\nct := resp.Header.Get(\"Content-Type\")\nif !strings.Contains(ct, \"application/json\") {\n    return fmt.Errorf(\"spinnaker returned non-JSON content-type %q — check auth/proxy\", ct)\n}\nresp.Body.Close()","typeGuard":null,"tryCatchPattern":"// Go: log the body when parsing fails\nasg, ids, err := sp.GetInstanceIDs(app, acct, cp, region, cluster)\nif err != nil && strings.Contains(err.Error(), \"failed to parse json\") {\n    log.Printf(\"spinnaker returned unexpected payload: %+v — check Spinnaker version and auth redirects\", err)\n}\nreturn asg, ids, err","preventionTips":["Pin the Spinnaker version compatible with your client library","Ensure auth is set so no login-page redirect occurs with 200","Check Content-Type before trusting JSON responses","Log raw bodies on parse failure for diagnosis"],"tags":["json","parsing","api-schema","spinnaker"],"backgroundTag":"schema-validation-failed","analyzedSha":"eaa28fb761c0ebe8644d1333e5d164e9cc3071e9","analyzedAt":"2026-09-03T17:04:39.020Z","contentChangedAt":"2026-09-03T17:04:39.020Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}