{"record":{"id":"2400aba1f90cd95f","repo":"t8y2/dbx","slug":"unexpected-management-api-response-for-list-endpoi","errorCode":null,"errorMessage":"Unexpected management API response for list endpoint %s","messagePattern":"Unexpected management API response for list endpoint (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/rabbitmq/management.go","lineNumber":160,"sourceCode":"func managementGetAll(connection jsonObject, path string) ([]any, error) {\n\tall := make([]any, 0)\n\tfor page := 1; ; page++ {\n\t\tseparator := \"?\"\n\t\tif strings.Contains(path, \"?\") {\n\t\t\tseparator = \"&\"\n\t\t}\n\t\tresponse, err := managementGet(connection,\n\t\t\tpath+separator+\"page=\"+strconv.Itoa(page)+\"&page_size=\"+strconv.Itoa(managementPageSize))\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tswitch typed := response.(type) {\n\t\tcase []any:\n\t\t\treturn append(all, typed...), nil\n\t\tcase map[string]any:\n\t\t\titems, exists := typed[\"items\"]\n\t\t\tif !exists {\n\t\t\t\treturn nil, fmt.Errorf(\"Unexpected management API response for list endpoint %s\", path)\n\t\t\t}\n\t\t\tif array, ok := items.([]any); ok {\n\t\t\t\tall = append(all, array...)\n\t\t\t}\n\t\t\tpageCount := integerOrNull(jsonObject(typed), \"page_count\")\n\t\t\tif pageCount == nil || page >= *pageCount {\n\t\t\t\treturn all, nil\n\t\t\t}\n\t\tdefault:\n\t\t\treturn nil, fmt.Errorf(\"Unexpected management API response for list endpoint %s\", path)\n\t\t}\n\t}\n}\n\nfunc managementBaseURLs(connection jsonObject) ([]string, error) {\n\tif explicit := stringOrNull(connection, \"management_url\"); explicit != nil && strings.TrimSpace(*explicit) != \"\" {\n\t\treturn []string{normalizeManagementURL(*explicit)}, nil\n\t}","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/rabbitmq/management.go#L142-L178","documentation":"managementGetAll pages through a RabbitMQ management API list endpoint and accepts either a plain JSON array or a paginated object with an \"items\" key; a map without \"items\" is an unexpected shape and returns this error naming the endpoint path. It guards against API changes or hitting a non-list resource.","triggerScenarios":"The management HTTP response for the given path is a JSON object lacking \"items\" — e.g. an error object like {\"error\":\"not_found\",\"reason\":\"...\"}, an authentication/API version payload, or the wrong URL returning a single-entity map.","commonSituations":"RabbitMQ management API version mismatch changing response shape; wrong vhost/path causing a not_found error object; unauthenticated response object; reverse proxy returning an HTML/JSON error map.","solutions":["Log/inspect the raw management response body for the endpoint to see the actual object","Fix the endpoint path/vhost (a 404 error object lacks \"items\")","Verify management API credentials and permissions","Check RabbitMQ version compatibility with the expected paginated response format"],"exampleFix":"// diagnose: the object was {\"error\":\"not_found\",\"reason\":\"...\"}\n// before\n\"http://localhost:15672/api/topics/%2F\"\n// after\n\"http://localhost:15672/api/exchanges/%2F\"","handlingStrategy":"type-guard","validationCode":"// preflight the endpoint with a raw request before paging\nresp, err := http.Get(baseURL + path)\nif err != nil { return err }\nbody, _ := io.ReadAll(resp.Body)\nif resp.StatusCode != http.StatusOK {\n    return fmt.Errorf(\"management endpoint %s unhealthy: %d %s\", path, resp.StatusCode, body)\n}","typeGuard":"func isPaginatedList(m map[string]any) bool {\n    _, ok := m[\"items\"].([]any)\n    return ok\n}\nfunc isPlainArray(v any) bool { _, ok := v.([]any); return ok }","tryCatchPattern":"all, err := managementGetAll(client, path)\nif err != nil && strings.Contains(err.Error(), \"Unexpected management API response\") {\n    log.Fatalf(\"endpoint %s returned unexpected shape; check RabbitMQ version and auth: %v\", path, err)\n}","preventionTips":["Check HTTP status before decoding JSON bodies in management calls","Log raw response bodies when the shape does not match expectations","Test against the RabbitMQ management API version you deploy","Handle error objects ({\"error\":...}) distinctly from list payloads"],"tags":["http","rabbitmq","management-api"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}