{"record":{"id":"2cae672f7c835d15","repo":"Netflix/chaosmonkey","slug":"unexpected-response-code-d-from-s-2cae67","errorCode":null,"errorMessage":"unexpected response code (%d) from %s","messagePattern":"unexpected response code \\((.+?)\\) from (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"spinnaker/spinnaker.go","lineNumber":269,"sourceCode":"}\n\n// GetInstanceIDs gets the instance ids for a cluster\nfunc (s Spinnaker) GetInstanceIDs(app string, account D.AccountName, cloudProvider string, region D.RegionName, cluster D.ClusterName) (D.ASGName, []D.InstanceID, error) {\n\turl := s.activeASGURL(app, string(account), string(cluster), cloudProvider, string(region))\n\n\tresp, err := s.client.Get(url)\n\tif err != nil {\n\t\treturn \"\", nil, errors.Wrapf(err, \"http get failed at %s\", url)\n\t}\n\n\tdefer func() {\n\t\tif cerr := resp.Body.Close(); cerr != nil && err == nil {\n\t\t\terr = errors.Wrapf(err, \"body close failed at %s\", url)\n\t\t}\n\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)","sourceCodeStart":251,"sourceCodeEnd":287,"githubUrl":"https://github.com/Netflix/chaosmonkey/blob/eaa28fb761c0ebe8644d1333e5d164e9cc3071e9/spinnaker/spinnaker.go#L251-L287","documentation":"Spinnaker.GetInstanceIDs throws this when the Spinnaker API responds with any HTTP status other than 200 OK for the active-ASG lookup. The library treats only 200 as success and includes the actual status code and URL in the message so the caller can diagnose whether the cluster, account, region, or provider inputs were wrong or the service is unhappy.","triggerScenarios":"Calling GetInstanceIDs with an app/account/cluster/region combination that does not exist (404), with bad credentials (401/403), when the Spinnaker server is overloaded (5xx), or when activeASGURL builds a path the API does not recognize.","commonSituations":"Typo or stale cluster/account name after infrastructure changes; app was deleted or renamed; Spinnaker gate returning 502/503 behind a proxy; auth token expired; API version change moved the endpoint.","solutions":["Read the status code from the error message; if 404, verify the app/account/cluster/region names exist in Spinnaker.","If 401/403, refresh credentials or check the client's auth configuration.","If 5xx, check Spinnaker gate/echo health and retry after the service recovers.","Curl the URL manually to compare the raw response with your inputs.","Regenerate the URL inputs (cluster naming conventions may have changed)."],"exampleFix":"// before\n_, ids, err := sp.GetInstanceIDs(\"myapp\", \"prod\", \"aws\", \"us-east-1\", \"myapp-prod\")\n// after\n// verify cluster exists first, then call\nclusters, _ := sp.GetClusterNames(\"myapp\", \"prod\")\nif contains(clusters, \"myapp-prod\") {\n    _, ids, err = sp.GetInstanceIDs(\"myapp\", \"prod\", \"aws\", \"us-east-1\", \"myapp-prod\")\n}","handlingStrategy":"validation","validationCode":"// verify the cluster/account/region inputs exist before the call\nclusters, err := sp.GetClusterNames(app, account)\nif err != nil {\n    return err\n}\nfound := false\nfor _, c := range clusters {\n    if c == cluster {\n        found = true\n        break\n    }\n}\nif !found {\n    return fmt.Errorf(\"cluster %q not found for app %q / account %q\", cluster, app, account)\n}","typeGuard":null,"tryCatchPattern":"// Go: branch on status code parsed from the message or re-check inputs\n_, _, err := sp.GetInstanceIDs(app, acct, cp, region, cluster)\nif err != nil {\n    var sErr interface{ Error() string }\n    if errors.As(err, &sErr) && strings.Contains(err.Error(), \"unexpected response code (4\") {\n        // 4xx: fix inputs/credentials, do not retry\n        return fmt.Errorf(\"bad request to spinnaker: %w\", err)\n    }\n    return err\n}","preventionTips":["Validate app/account/cluster/region names against the API before calls","Refresh credentials before expiry","Pin Spinnaker API compatibility with your library version","Curl the endpoint when diagnosing to see the raw status"],"tags":["http","api","status-code","spinnaker"],"backgroundTag":"unexpected-http-status","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"}