{"record":{"id":"2f5ab22fb6b09629","repo":"hashicorp/terraform","slug":"failed-to-select-workspace-s","errorCode":null,"errorMessage":"Failed to select workspace: %s","messagePattern":"Failed to select workspace: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/meta_backend.go","lineNumber":312,"sourceCode":"\t\tlog.Printf(\"[TRACE] Meta.selectWorkspace: automatically selecting the single workspace provided by the backend (%s)\", workspaces[0])\n\t\treturn m.SetWorkspace(workspaces[0])\n\t}\n\n\tif !m.input {\n\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","sourceCodeStart":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/meta_backend.go#L294-L330","documentation":"Returned from `Meta.selectWorkspace` when the interactive workspace-selection prompt (`UIInput().Input` with id `select-workspace`) itself returns an error. The user was shown the numbered list of existing workspaces but the input mechanism failed before a choice could be read. Distinct from error 655 (invalid choice) — here the prompt never returned a value.","triggerScenarios":"`UIInput().Input` errors due to stdin closure, interrupt (Ctrl-C), a non-TTY with input enabled but no piped value, or an internal UIInput error. The workspace list was built and displayed, but reading the selection failed.","commonSituations":"An interrupt during workspace selection; stdin closed by a wrapper; running interactively but a terminal multiplexer detached mid-prompt.","solutions":["Avoid the prompt by pre-selecting: `terraform workspace select <name>` or `TF_WORKSPACE=<name>`.","Re-run in a stable terminal and answer the prompt promptly.","Use `-input=false` with an explicitly selected workspace so the prompt is never shown."],"exampleFix":"# before: prompt errors mid-selection\nterraform plan\n# after: pre-select\nterraform workspace select prod\nterraform plan","handlingStrategy":"validation","validationCode":"// Avoid the selection prompt by pre-selecting a workspace.\nif err := m.SetWorkspace(wanted); err != nil { return err }\n// then run with -input=false to skip prompts","typeGuard":"null","tryCatchPattern":"// UIInput errors are not retryable; pre-select the workspace to avoid the prompt.","preventionTips":["Use `terraform workspace select` before operations.","Set `TF_WORKSPACE` explicitly.","Run in a stable terminal; avoid interrupts during prompts."],"tags":["terraform","workspace","input","interactive","ui"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}