{"record":{"id":"f1bafd6634583462","repo":"t8y2/dbx","slug":"unexpected-management-api-response-for-vhost-listi","errorCode":null,"errorMessage":"Unexpected management API response for vhost listing","messagePattern":"Unexpected management API response for vhost listing","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/rabbitmq/operations.go","lineNumber":310,"sourceCode":"\t\t\tentry[\"prefetch\"] = *prefetch\n\t\t}\n\t\tconsumers = append(consumers, entry)\n\t}\n\treturn consumers\n}\n\nfunc (s *server) listNamespaces(params jsonObject) (any, error) {\n\tconnection, err := s.requireConnectionConfig(params)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tvhosts, err := managementGet(connection, \"/api/vhosts\")\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tarray, ok := vhosts.([]any)\n\tif !ok {\n\t\treturn nil, errors.New(\"Unexpected management API response for vhost listing\")\n\t}\n\tnamespaces := make([]jsonObject, 0, len(array))\n\tfor _, value := range array {\n\t\tvhost, ok := value.(map[string]any)\n\t\tif ok {\n\t\t\tnamespaces = append(namespaces, jsonObject{\"name\": stringOrEmpty(jsonObject(vhost), \"name\")})\n\t\t}\n\t}\n\treturn jsonObject{\"namespaces\": namespaces}, nil\n}\n\nfunc (s *server) createNamespace(params jsonObject) (any, error) {\n\tnamespace, err := namespaceName(params)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tconnection, err := s.requireConnectionConfig(params)\n\tif err != nil {","sourceCodeStart":292,"sourceCodeEnd":328,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/rabbitmq/operations.go#L292-L328","documentation":"listNamespaces calls the RabbitMQ management API endpoint /api/vhosts and expects the JSON response to decode into a JSON array. This error is thrown when the decoded response is not an []any (e.g. the management API returned an object such as {\"error\":\"...\"}, an error payload, or an unexpected shape) instead of a vhost array. It indicates the management API responded successfully at the HTTP layer but with data the driver cannot interpret as a vhost listing.","triggerScenarios":"managementGet(connection, \"/api/vhosts\") returns a decoded value that fails the type assertion vhosts.([]any) — typically because the management endpoint returned a JSON object (auth error body, HTML/plain-text error page, proxy response, or a non-standard management plugin response) instead of an array of vhosts.","commonSituations":"Wrong management API port or reverse proxy returning an error page; management credentials valid for HTTP but the endpoint path changed across RabbitMQ versions; a load balancer or management UI returning JSON error objects; pointing the agent at the AMQP port instead of the management HTTP port.","solutions":["Verify the connection points at the RabbitMQ management HTTP port (default 15672), not the AMQP port, and that the management plugin is enabled (rabbitmq-plugins enable rabbitmq_management).","Check management credentials: log in with the same user via curl -u user:pass http://host:15672/api/vhosts and confirm a JSON array is returned.","Inspect any proxy/load balancer in front of the management API that may rewrite or block /api/vhosts.","Log the raw managementGet response body when this occurs to see what the server actually returned, then update the driver's decoding if the API shape changed."],"exampleFix":"// before\narray, ok := vhosts.([]any)\nif !ok {\n    return nil, errors.New(\"Unexpected management API response for vhost listing\")\n}\n// after\narray, ok := vhosts.([]any)\nif !ok {\n    return nil, fmt.Errorf(\"Unexpected management API response for vhost listing: got %T: %v\", vhosts, vhosts)\n}","handlingStrategy":"type-guard","validationCode":"// Pre-check management API reachability/shape before calling listNamespaces\nresp, err := http.Get(\"http://host:15672/api/vhosts\") // with auth in practice\nif err != nil || resp.StatusCode != 200 {\n    return fmt.Errorf(\"management API not healthy: status %v\", resp.StatusCode)\n}","typeGuard":"func isVhostArray(v any) bool {\n    arr, ok := v.([]any)\n    if !ok { return false }\n    for _, item := range arr {\n        if _, ok := item.(map[string]any); !ok { return false }\n    }\n    return true\n}","tryCatchPattern":"namespaces, err := agent.Call(\"listNamespaces\", params)\nif err != nil {\n    if strings.Contains(err.Error(), \"Unexpected management API response\") {\n        // log raw response, check management port/plugin/credentials, retry after fix\n        return fmt.Errorf(\"management API returned non-array payload; verify port 15672 and rabbitmq_management plugin: %w\", err)\n    }\n    return err\n}","preventionTips":["Point the agent at the management HTTP port (15672) and enable rabbitmq_management.","curl /api/vhosts with your credentials and confirm a JSON array is returned before wiring the agent.","Check for proxies/load balancers that can replace the response body on errors.","Keep RabbitMQ and the driver in versions whose management API response shapes match."],"tags":["rabbitmq","management-api","response-parsing","http"],"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"}