{"record":{"id":"c0c83bd3897b9dd9","repo":"t8y2/dbx","slug":"the-default-virtual-host-cannot-be-deleted","errorCode":null,"errorMessage":"The default virtual host '/' cannot be deleted","messagePattern":"The default virtual host '/' cannot be deleted","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/rabbitmq/operations.go","lineNumber":371,"sourceCode":"\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) {\n\tconnection, err := s.requireConnectionConfig(params)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tallVhosts := allVhostsRequested(params)\n\texchanges, err := managementGetAll(connection, managementListPath(params, connection, \"exchanges\"))\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tresult := make([]jsonObject, 0, len(exchanges))","sourceCodeStart":353,"sourceCodeEnd":389,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/rabbitmq/operations.go#L353-L389","documentation":"assertNamespaceDeletable protects the default RabbitMQ virtual host '/'. RabbitMQ ships with '/' and deleting it would break default connections and client configs, so the driver refuses up front with this error instead of sending a doomed DELETE to the management API.","triggerScenarios":"Calling deleteNamespace with namespace == \"/\".","commonSituations":"Iterating all vhosts from listNamespaces (which includes '/') and deleting each; a cleanup script targeting every vhost; users misreading '/' as 'all vhosts' or an empty root.","solutions":["Skip the '/' vhost in your deletion loop: if ns == \"/\" { continue }.","Delete only explicitly-named application vhosts, never the default one.","If '/' is truly unwanted, recreate the broker/node rather than deleting the default vhost."],"exampleFix":"// before\nfor _, vhost := range vhosts {\n    agent.Call(\"deleteNamespace\", map[string]any{\"namespace\": vhost[\"name\"]})\n}\n// after\nfor _, vhost := range vhosts {\n    if vhost[\"name\"] == \"/\" {\n        continue\n    }\n    agent.Call(\"deleteNamespace\", map[string]any{\"namespace\": vhost[\"name\"]})\n}","handlingStrategy":"validation","validationCode":"func assertDeletableVhost(ns string) error {\n    if ns == \"/\" {\n        return errors.New(\"refusing to delete the default virtual host '/'\")\n    }\n    return nil\n}","typeGuard":"func isCustomVhost(ns string) bool {\n    return ns != \"\" && ns != \"/\"\n}","tryCatchPattern":"_, err := agent.Call(\"deleteNamespace\", map[string]any{\"namespace\": ns})\nif err != nil {\n    if strings.Contains(err.Error(), \"default virtual host\") {\n        // skip or abort; '/' must remain\n        return nil\n    }\n    return err\n}","preventionTips":["Filter out '/' before looping over listNamespaces results.","Document '/' as off-limits in cleanup scripts.","Restrict the management user's permissions so it cannot delete '/' as a second line of defense."],"tags":["rabbitmq","vhost","protection","validation"],"backgroundTag":"protected-resource-deletion","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"}