{"record":{"id":"0aa89e6419895ba8","repo":"hashicorp/terraform","slug":"the-workspace-name-q-is-not-allowed-the-name-mu","errorCode":null,"errorMessage":"\nThe workspace name %q is not allowed. The name must contain only URL safe\ncharacters, contain no path separators, and not be an empty string.\n","messagePattern":"\nThe workspace name %q is not allowed\\. The name must contain only URL safe\ncharacters, contain no path separators, and not be an empty string\\.\n","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/arguments/workspace_new.go","lineNumber":59,"sourceCode":"\t\tdiags = diags.Append(tfdiags.Sourceless(\n\t\t\ttfdiags.Error,\n\t\t\t\"Failed to parse command-line flags\",\n\t\t\terr.Error(),\n\t\t))\n\t}\n\n\t// `workspace new` takes only one positional argument: workspace name.\n\targs = cmdFlags.Args()\n\tif len(args) != 1 {\n\t\tdiags = diags.Append(errors.New(\"Expected a single argument: NAME.\")) // Recreating pre-existing error from command package\n\t}\n\n\t// Obtain and validate name argument, but only if there is the expected number of arguments.\n\tvar name string\n\tif len(args) == 1 {\n\t\tname = args[0]\n\t\tif !ValidWorkspaceName(name) {\n\t\t\tdiags = diags.Append(fmt.Errorf(EnvInvalidName, name))\n\t\t}\n\t}\n\n\treturn &WorkspaceNew{\n\t\tWorkspace:   Workspace{ViewType: ViewHuman},\n\t\tName:        name,\n\t\tLock:        stateLock,\n\t\tLockTimeout: stateLockTimeout,\n\t\tStatePath:   statePath,\n\t}, diags\n}\n","sourceCodeStart":41,"sourceCodeEnd":71,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/arguments/workspace_new.go#L41-L71","documentation":"Emitted by `terraform workspace new` (workspace_new.go:58-59) when the supplied name fails `ValidWorkspaceName`. That function (workspace.go:19-24) requires the name be non-empty AND equal to its own `url.PathEscape`, i.e. contain only URL-safe characters and no path separators. The message text is the shared `EnvInvalidName` constant.","triggerScenarios":"Calling `terraform workspace new <name>` where `<name>` contains spaces, slashes (`/`, `\\`), colons, or other characters that change under `url.PathEscape`, or is empty.","commonSituations":"Naming workspaces after git branch names containing `/` (e.g. `feature/x`); using uppercase or special chars that are not URL-path-safe; passing an empty string.","solutions":["Use only URL-safe, path-separator-free characters (letters, digits, `-`, `_`).","Replace separators in derived names, e.g. convert `feature/x` to `feature-x`.","Verify with: the name must satisfy `name == url.PathEscape(name)` and `name != \"\"`."],"exampleFix":"# before\nterraform workspace new \"feature/login\"\n# The workspace name \"feature/login\" is not allowed ...\n\n# after\nterraform workspace new \"feature-login\"","handlingStrategy":"validation","validationCode":"// Mirror internal/command/arguments.ValidWorkspaceName before calling 'workspace new'.\nimport \"net/url\"\n\nfunc validWorkspaceName(name string) bool {\n    if name == \"\" {\n        return false\n    }\n    return name == url.PathEscape(name)\n}\n\nfunc sanitizeWorkspaceName(raw string) (string, error) {\n    replacer := strings.NewReplacer(\"/\", \"-\", \"\\\\\", \"-\", \" \", \"-\")\n    name := replacer.Replace(raw)\n    if !validWorkspaceName(name) {\n        return \"\", fmt.Errorf(\"invalid workspace name %q\", raw)\n    }\n    return name, nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Derive workspace names from branch names by replacing `/` and whitespace.","Run the name through `url.PathEscape` equality before invoking the CLI.","Restrict generated names to `[A-Za-z0-9_-]`."],"tags":["terraform","workspace","new","validation","naming"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}