{"record":{"id":"45d4bdd6d2e0eafc","repo":"hashicorp/nomad","slug":"invalid-namespace-q-v","errorCode":null,"errorMessage":"Invalid namespace %q: %v","messagePattern":"Invalid namespace %q: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/namespace_endpoint.go","lineNumber":64,"sourceCode":"\n\tdefer metrics.MeasureSince([]string{\"nomad\", \"namespace\", \"upsert_namespaces\"}, time.Now())\n\n\t// Check management permissions\n\tif aclObj, err := n.srv.ResolveACL(args); err != nil {\n\t\treturn err\n\t} else if !aclObj.IsManagement() {\n\t\treturn structs.ErrPermissionDenied\n\t}\n\n\t// Validate there is at least one namespace\n\tif len(args.Namespaces) == 0 {\n\t\treturn fmt.Errorf(\"must specify at least one namespace\")\n\t}\n\n\t// Validate the namespaces and set the hash\n\tfor _, ns := range args.Namespaces {\n\t\tif err := ns.Validate(); err != nil {\n\t\t\treturn fmt.Errorf(\"Invalid namespace %q: %v\", ns.Name, err)\n\t\t}\n\n\t\tns.SetHash()\n\t}\n\n\t// Update via Raft\n\t_, index, err := n.srv.raftApply(structs.NamespaceUpsertRequestType, args)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t// Update the index\n\treply.Index = index\n\treturn nil\n}\n\n// DeleteNamespaces is used to delete a namespace\nfunc (n *Namespace) DeleteNamespaces(args *structs.NamespaceDeleteRequest, reply *structs.GenericResponse) error {","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/namespace_endpoint.go#L46-L82","documentation":"Each namespace in an UpsertNamespaces batch is validated with ns.Validate() before the Raft write; on the first invalid namespace the endpoint aborts with this wrapped error naming the namespace and the underlying validation reason (e.g. bad name characters, missing fields).","triggerScenarios":"Upserting one or more namespaces whose Validate() fails — invalid Name (empty, illegal characters), invalid quota, hash/fields rejected by the namespace schema.","commonSituations":"Names containing uppercase or special characters not allowed by Nomad namespace naming rules; a namespace struct built with an unset Name; quota references pointing at nonexistent quotas; IaC interpolating malformed names from branch names or labels.","solutions":["Read the wrapped %v detail to see which field failed validation and correct that field on the named namespace.","Use a valid name: lowercase alphanumeric with hyphens/underscores, non-empty, within length limits.","Call ns.Validate() client-side before submitting the batch to catch failures early.","Check generated names from automation (branch/label interpolation) for illegal characters."],"exampleFix":"// before\nns := &structs.Namespace{Name: \"Prod Team!\", Description: \"...\"}\n// after\nns := &structs.Namespace{Name: \"prod-team\", Description: \"...\"}\nif err := ns.Validate(); err != nil { return err }","handlingStrategy":"validation","validationCode":"for _, ns := range namespaces {\n    if err := ns.Validate(); err != nil {\n        return fmt.Errorf(\"namespace %q invalid: %w\", ns.Name, err)\n    }\n}","typeGuard":"func validNamespaceName(name string) bool {\n    if name == \"\" || len(name) > 128 { return false }\n    for _, r := range name {\n        if !(r == '-' || r == '_' || r >= 'a' && r <= 'z' || r >= '0' && r <= '9') { return false }\n    }\n    return true\n}","tryCatchPattern":"_, err := client.Namespaces().Upsert(req, nil)\nif err != nil {\n    var nsName, reason string\n    if _, scanErr := fmt.Sscanf(err.Error(), \"Invalid namespace %q: %v\", &nsName, &reason); scanErr == nil {\n        return fmt.Errorf(\"fix namespace %s: %s\", nsName, reason)\n    }\n}\nreturn err","preventionTips":["Validate namespaces client-side (ns.Validate) before batch submission.","Constrain automated name generation (branch/label interpolation) to allowed characters.","Verify referenced quotas exist before upserting namespaces.","Upsert in small batches so one bad namespace doesn't block the whole set."],"tags":["nomad","namespace","validation","schema"],"backgroundTag":"schema-validation-failed","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}