{"record":{"id":"dbbb2ab85c3c41d9","repo":"t8y2/dbx","slug":"unexpected-management-api-response-for-permission","errorCode":null,"errorMessage":"Unexpected management API response for permission listing","messagePattern":"Unexpected management API response for permission listing","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/rabbitmq/operations.go","lineNumber":869,"sourceCode":"func assertNotConnectedUser(action, name, connectedUser string) error {\n\tif name == connectedUser {\n\t\treturn fmt.Errorf(\"Cannot %s user '%s' while connected as that user\", action, name)\n\t}\n\treturn nil\n}\n\nfunc (s *server) listPermissions(params jsonObject) (any, error) {\n\tconnection, err := s.requireConnectionConfig(params)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tpermissions, err := managementGet(connection, \"/api/permissions\")\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tarray, ok := permissions.([]any)\n\tif !ok {\n\t\treturn nil, errors.New(\"Unexpected management API response for permission listing\")\n\t}\n\tvhostFilter := stringOrEmpty(params, \"virtual_host\")\n\tif allVhostsRequested(params) {\n\t\tvhostFilter = \"\"\n\t}\n\tuserFilter := stringOrEmpty(params, \"user\")\n\tresult := make([]jsonObject, 0, len(array))\n\tfor _, value := range array {\n\t\tpermission, ok := value.(map[string]any)\n\t\tif !ok {\n\t\t\tcontinue\n\t\t}\n\t\tinfo := permissionInfoFromJSON(jsonObject(permission))\n\t\tif vhostFilter != \"\" && vhostFilter != stringOrEmpty(info, \"vhost\") {\n\t\t\tcontinue\n\t\t}\n\t\tif userFilter != \"\" && userFilter != stringOrEmpty(info, \"user\") {\n\t\t\tcontinue","sourceCodeStart":851,"sourceCodeEnd":887,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/rabbitmq/operations.go#L851-L887","documentation":"listPermissions calls GET /api/permissions via managementGet and expects the JSON response to decode into a []any array. If the response is not an array (e.g. an error object, null, or an unexpected shape), the type assertion fails and the library raises this error instead of returning malformed data. It signals a mismatch between expected and actual management API response shape.","triggerScenarios":"The RabbitMQ management API returns a non-array body for GET /api/permissions — for example an error JSON object (401/403/404 payloads), a proxy/gateway error page, or a management plugin version/endpoint change that returns a different structure.","commonSituations":"Wrong vhost or insufficient permissions causing the management API to return an error object rather than the list; connecting through a reverse proxy or load balancer that intercepts the request (auth walls, HTML error pages); RabbitMQ management plugin version differences; targeting a non-management port or endpoint that answers with a different payload.","solutions":["Inspect the management API response directly (curl with management credentials to /api/permissions) to see what is actually returned.","Verify management API credentials and permissions — an auth error object instead of the array is the most common cause.","Confirm the management plugin is enabled and you are hitting the correct management API port (default 15672), not the AMQP port or a proxy.","Upgrade/align the driver with your RabbitMQ server version if the endpoint response shape changed."],"exampleFix":"// before\nresp, err := http.Get(baseURL + \"/api/permissions\") // hits proxy error page, body is HTML/object\npermissions, err := managementGet(connection, \"/api/permissions\")\n// after: verify endpoint and auth first\ncurl -u user:pass http://localhost:15672/api/permissions\n// and only then, via the driver:\npermissions, err := managementGet(connection, \"/api/permissions\")","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"func isPermissionList(resp any) bool {\n    _, ok := resp.([]any)\n    return ok\n}\n// usage:\n// if !isPermissionList(permissions) { /* handle unexpected shape, log raw resp */ }","tryCatchPattern":"permissions, err := listPermissions(params)\nif err != nil {\n    if err.Error() == \"Unexpected management API response for permission listing\" {\n        log.Printf(\"management API returned unexpected shape; check credentials/proxy, raw: %v\", permissions)\n        return fallbackPermissionCheck()\n    }\n    return err\n}","preventionTips":["Verify management API credentials and vhost permissions before listing (401/403 bodies are objects, not arrays).","Confirm the management plugin is enabled and you target the management port (15672), bypassing intercepting proxies.","Pin and test against your RabbitMQ server version so response-shape changes are caught in CI.","Log the raw response body when this error fires to diagnose the actual payload."],"tags":["rabbitmq","management-api","unexpected-response","type-assertion"],"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"}