{"record":{"id":"427fb87ad037e0e2","repo":"t8y2/dbx","slug":"namespace-is-required","errorCode":null,"errorMessage":"namespace is required","messagePattern":"namespace is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/rabbitmq/operations.go","lineNumber":361,"sourceCode":"\t\treturn nil, err\n\t}\n\tconnection, err := s.requireConnectionConfig(params)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif err := assertNamespaceDeletable(namespace, stringOrDefault(connection, \"virtual_host\", \"/\")); err != nil {\n\t\treturn nil, err\n\t}\n\tif _, err := managementSend(connection, http.MethodDelete, \"/api/vhosts/\"+urlEncodeVhost(namespace), nil); err != nil {\n\t\treturn nil, err\n\t}\n\treturn okResult(), nil\n}\n\nfunc namespaceName(params jsonObject) (string, error) {\n\tname := stringOrEmpty(params, \"namespace\")\n\tif strings.TrimSpace(name) == \"\" {\n\t\treturn \"\", errors.New(\"namespace is required\")\n\t}\n\tif strings.TrimSpace(name) == \"*\" {\n\t\treturn \"\", errors.New(\"namespace create/delete requires a specific virtual host (all-vhosts context)\")\n\t}\n\treturn name, nil\n}\n\nfunc assertNamespaceDeletable(namespace, connectedVhost string) error {\n\tif namespace == \"/\" {\n\t\treturn errors.New(\"The default virtual host '/' cannot be deleted\")\n\t}\n\tif connectedVhost != \"\" && namespace == connectedVhost {\n\t\treturn fmt.Errorf(\"Cannot delete the virtual host '%s' while connected to it\", namespace)\n\t}\n\treturn nil\n}\n\nfunc (s *server) listExchanges(params jsonObject) (any, error) {","sourceCodeStart":343,"sourceCodeEnd":379,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/rabbitmq/operations.go#L343-L379","documentation":"namespaceName extracts the 'namespace' parameter (which maps to a RabbitMQ virtual host) for create/delete operations and rejects it when it is missing or only whitespace. The driver requires an explicit target vhost; it will not guess one. Callers (createNamespace, deleteNamespace) always funnel through this guard.","triggerScenarios":"Calling createNamespace or deleteNamespace without a 'namespace' key in params, or with namespace:\"\", \"   \", or null.","commonSituations":"Building the params map dynamically and forgetting the namespace key; copying an example that used a different param name (e.g. 'vhost' or 'name'); a config/UI layer passing an empty selection through.","solutions":["Pass params[\"namespace\"] with the target virtual host name, e.g. {\"namespace\": \"my-vhost\"}.","Trim and validate the namespace value at your call site before invoking the driver.","If the namespace comes from user input or config, fail fast with a clear message when it is empty."],"exampleFix":"// before\nagent.Call(\"createNamespace\", map[string]any{})\n// after\nagent.Call(\"createNamespace\", map[string]any{\"namespace\": \"my-vhost\"})","handlingStrategy":"validation","validationCode":"func requireNamespace(params map[string]any) error {\n    ns, _ := params[\"namespace\"].(string)\n    if strings.TrimSpace(ns) == \"\" {\n        return errors.New(\"caller validation: namespace must be a non-empty vhost name\")\n    }\n    return nil\n}","typeGuard":"func hasNamespace(params map[string]any) bool {\n    ns, ok := params[\"namespace\"].(string)\n    return ok && strings.TrimSpace(ns) != \"\"\n}","tryCatchPattern":"result, err := agent.Call(\"createNamespace\", params)\nif err != nil {\n    if err.Error() == \"namespace is required\" {\n        return fmt.Errorf(\"createNamespace requires params.namespace (target virtual host)\")\n    }\n    return err\n}","preventionTips":["Always set params[\"namespace\"] for createNamespace/deleteNamespace.","Use a single params-builder helper so required keys can't be forgotten.","Validate config-derived namespaces are non-empty at startup.","Don't rename the key to 'vhost' or 'name' in your call sites."],"tags":["rabbitmq","validation","missing-parameter","vhost"],"backgroundTag":"missing-required-parameter","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}