{"record":{"id":"ec6ebdd005675d9d","repo":"hashicorp/terraform","slug":"failed-to-select-workspace-input-not-a-valid-numb","errorCode":null,"errorMessage":"Failed to select workspace: input not a valid number","messagePattern":"Failed to select workspace: input not a valid number","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/command/meta_backend.go","lineNumber":317,"sourceCode":"\t\treturn fmt.Errorf(\"Currently selected workspace %q does not exist\", workspace)\n\t}\n\n\t// Otherwise, ask the user to select a workspace from the list of existing workspaces.\n\tv, err := m.UIInput().Input(context.Background(), &terraform.InputOpts{\n\t\tId: \"select-workspace\",\n\t\tQuery: fmt.Sprintf(\n\t\t\t\"\\n[reset][bold][yellow]The currently selected workspace (%s) does not exist.[reset]\",\n\t\t\tworkspace),\n\t\tDescription: fmt.Sprintf(\n\t\t\tstrings.TrimSpace(inputBackendSelectWorkspace), list.String()),\n\t})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"Failed to select workspace: %s\", err)\n\t}\n\n\tidx, err := strconv.Atoi(v)\n\tif err != nil || (idx < 1 || idx > len(workspaces)) {\n\t\treturn fmt.Errorf(\"Failed to select workspace: input not a valid number\")\n\t}\n\n\tworkspace = workspaces[idx-1]\n\tlog.Printf(\"[TRACE] Meta.selectWorkspace: setting the current workspace according to user selection (%s)\", workspace)\n\treturn m.SetWorkspace(workspace)\n}\n\n// BackendForLocalPlan is similar to Backend, but uses settings that were\n// stored in a plan when preparing the returned operations backend.\n// The plan's data may describe `backend` or `state_store` configuration.\n//\n// The current workspace name is also stored as part of the plan, and so this\n// method will check that it matches the currently-selected workspace name\n// and produce error diagnostics if not.\nfunc (m *Meta) BackendForLocalPlan(plan *plans.Plan) (backendrun.OperationsBackend, tfdiags.Diagnostics) {\n\tvar diags tfdiags.Diagnostics\n\n\t// Check the workspace name in the plan matches the current workspace","sourceCodeStart":299,"sourceCodeEnd":335,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/meta_backend.go#L299-L335","documentation":"Returned by selectWorkspace() when the user's response to the numbered workspace-selection prompt is not a valid integer, or is out of range. strconv.Atoi fails (non-numeric) or the parsed index is <1 or >len(workspaces). This is a pure input-validation failure on interactive selection.","triggerScenarios":"At the 'The currently selected workspace does not exist' numbered prompt, the user enters a non-numeric string, a number less than 1, or a number greater than the listed workspace count.","commonSituations":"User types the workspace name instead of its number; typos; zero or negative numbers; copying a stale list where the indices shifted.","solutions":["Re-run and enter a number between 1 and the count shown in the prompt list.","Avoid the prompt entirely by pre-selecting with `terraform workspace select <name>`."],"exampleFix":"// before: typed name instead of number\n> 1. dev  2. prod\n> prod\n// after\n> 2","handlingStrategy":"validation","validationCode":"// If scripting the prompt, validate the numeric choice beforehand\nif idx, err := strconv.Atoi(choice); err != nil || idx < 1 || idx > len(workspaces) {\n    return fmt.Errorf(\"invalid selection %q; must be 1..%d\", choice, len(workspaces))\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Enter the number (not the name) shown in the prompt list.","Avoid the prompt by pre-selecting with `terraform workspace select <name>`."],"tags":["workspace","interactive","validation","select"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}