{"record":{"id":"96c2b89b560e0e41","repo":"hashicorp/terraform","slug":"expected-a-single-argument-name-96c2b8","errorCode":null,"errorMessage":"Expected a single argument: NAME.","messagePattern":"Expected a single argument: NAME\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/arguments/workspace_new.go","lineNumber":51,"sourceCode":"\tvar stateLock bool\n\tvar stateLockTimeout time.Duration\n\tvar statePath string\n\tcmdFlags := defaultFlagSet(\"workspace new\")\n\tcmdFlags.BoolVar(&stateLock, \"lock\", true, \"lock state\")\n\tcmdFlags.DurationVar(&stateLockTimeout, \"lock-timeout\", 0, \"lock timeout\")\n\tcmdFlags.StringVar(&statePath, \"state\", \"\", \"terraform state file\")\n\tif err := cmdFlags.Parse(args); err != nil {\n\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","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/arguments/workspace_new.go#L33-L69","documentation":"Returned by ParseWorkspaceNew (workspace_new.go:51) when, after flag parsing, the number of positional arguments is not exactly one — i.e. 'terraform workspace new' was called with zero or more than one name. The command requires exactly one workspace NAME (then optionally validated by ValidWorkspaceName).","triggerScenarios":"Line 49-51: len(args) != 1 after cmdFlags.Parse; covers both 'too few' and 'too many' positional names.","commonSituations":"Running 'terraform workspace new' with no name; passing flags after the name in a way that confuses the parser; attempting to create several workspaces at once.","solutions":["Provide exactly one workspace name: 'terraform workspace new NAME'.","Create additional workspaces with separate invocations.","Verify the name passes workspace naming rules (ValidWorkspaceName) to avoid a follow-on error."],"exampleFix":"# before\n$ terraform workspace new\n# after\n$ terraform workspace new my-workspace","handlingStrategy":"validation","validationCode":"// 'workspace new' requires exactly one NAME.\nfunc validateNewArgs(args []string) error {\n    if len(args) != 1 {\n        return fmt.Errorf(\"workspace new takes exactly one NAME, got %d\", len(args))\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass exactly one workspace name to 'terraform workspace new'.","Create multiple workspaces with separate invocations.","Validate the name against workspace naming rules beforehand."],"tags":["cli-arguments","workspace","new","missing-argument"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}