{"record":{"id":"38a279803f357597","repo":"hashicorp/nomad","slug":"invalid-name-q-must-match-regex-s-38a279","errorCode":null,"errorMessage":"invalid name %q. Must match regex %s","messagePattern":"invalid name %q\\. Must match regex (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/structs.go","lineNumber":5659,"sourceCode":"\t// is provided only the namespace's default node pool is allowed. This field\n\t// supports wildcard globbing through the use of `*` for multi-character\n\t// matching. This field cannot be used with Denied.\n\tAllowed []string\n\n\t// Denied specifies the node pools that are not allowed to be used by jobs\n\t// in this namespace. This field supports wildcard globbing through the use\n\t// of `*` for multi-character matching. If specified, any node pool is\n\t// allowed to be used, except for those that match any of these patterns.\n\t// This field cannot be used with Allowed.\n\tDenied []string\n}\n\nfunc (n *Namespace) Validate() error {\n\tvar mErr multierror.Error\n\n\t// Validate the name and description\n\tif !validNamespaceName.MatchString(n.Name) {\n\t\terr := fmt.Errorf(\"invalid name %q. Must match regex %s\", n.Name, validNamespaceName)\n\t\tmErr.Errors = append(mErr.Errors, err)\n\t}\n\tif len(n.Description) > maxNamespaceDescriptionLength {\n\t\terr := fmt.Errorf(\"description longer than %d\", maxNamespaceDescriptionLength)\n\t\tmErr.Errors = append(mErr.Errors, err)\n\t}\n\n\terr := n.NodePoolConfiguration.Validate()\n\tswitch e := err.(type) {\n\tcase *multierror.Error:\n\t\tfor _, npErr := range e.Errors {\n\t\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"invalid node pool configuration: %v\", npErr))\n\t\t}\n\tcase error:\n\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"invalid node pool configuration: %v\", e))\n\t}\n\n\terr = n.VaultConfiguration.Validate()","sourceCodeStart":5641,"sourceCodeEnd":5677,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/structs.go#L5641-L5677","documentation":"This error is produced by Namespace.Validate() in nomad/structs when a Namespace's Name fails the validNamespaceName regex (^[a-zA-Z0-9-]{1,128}$). Nomad namespace names may only contain alphanumerics and hyphens, 1-128 chars. The error is accumulated into a multierror and returned to the caller of namespace create/update APIs.","triggerScenarios":"Calling nomad namespace apply/create (CLI, HTTP /v1/namespaces, or structs.Namespace.Validate directly) with a name containing spaces, underscores, dots, slashes, unicode, or exceeding 128 characters, or an empty name.","commonSituations":"Terraform/Nomad job files or HCL namespace blocks with names like 'my_team' or 'team.eu'; scripting that derives namespace names from directory names; copying names with trailing whitespace.","solutions":["Rename the namespace to contain only a-z, A-Z, 0-9, and '-' (max 128 chars)","Remove surrounding whitespace and illegal characters (e.g. replace '_' with '-')","If upgrading from an older Nomad, check that pre-existing names still match the regex before API calls","Validate names in your provisioning code before submitting via the Nomad API"],"exampleFix":"// before\nns := &structs.Namespace{Name: \"prod_eu\"}\n// after\nns := &structs.Namespace{Name: \"prod-eu\"}","handlingStrategy":"validation","validationCode":"var validNamespaceName = regexp.MustCompile(`^[a-zA-Z0-9-]{1,128}$`)\nif !validNamespaceName.MatchString(name) {\n    return fmt.Errorf(\"namespace name %q invalid: use only alphanumerics and hyphens (1-128 chars)\", name)\n}","typeGuard":"func isValidNamespaceName(name string) bool {\n    return regexp.MustCompile(`^[a-zA-Z0-9-]{1,128}$`).MatchString(name)\n}","tryCatchPattern":null,"preventionTips":["Regex-check names in IaC (Terraform/CI) before applying","Replace underscores/dots with hyphens when generating names from paths","Trim whitespace from names sourced from env vars or filenames","Keep a lint rule rejecting illegal namespace names"],"tags":["nomad","validation","namespace"],"backgroundTag":"namespace-name-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"}