{"record":{"id":"409683487110dfc6","repo":"hashicorp/terraform","slug":"error-loading-workspace-w","errorCode":null,"errorMessage":"error loading workspace: %w","messagePattern":"error loading workspace: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/backend/remote/backend_context.go","lineNumber":108,"sourceCode":"\tif op.AllowUnsetVariables {\n\t\t// If we're not going to use the variables in an operation we'll be\n\t\t// more lax about them, stubbing out any unset ones as unknown.\n\t\t// This gives us enough information to produce a consistent context,\n\t\t// but not enough information to run a real operation (plan, apply, etc)\n\t\tret.PlanOpts.SetVariables = stubAllVariables(op.Variables, rootMod.Variables)\n\t} else {\n\t\t// The underlying API expects us to use the opaque workspace id to request\n\t\t// variables, so we'll need to look that up using our organization name\n\t\t// and workspace name.\n\t\tremoteWorkspaceID, err := b.getRemoteWorkspaceID(context.Background(), op.Workspace)\n\t\tif err != nil {\n\t\t\tdiags = diags.Append(fmt.Errorf(\"error finding remote workspace: %w\", err))\n\t\t\treturn nil, nil, diags\n\t\t}\n\n\t\tw, err := b.fetchWorkspace(context.Background(), b.organization, op.Workspace)\n\t\tif err != nil {\n\t\t\tdiags = diags.Append(fmt.Errorf(\"error loading workspace: %w\", err))\n\t\t\treturn nil, nil, diags\n\t\t}\n\n\t\tif isLocalExecutionMode(w.ExecutionMode) {\n\t\t\tlog.Printf(\"[TRACE] skipping retrieving variables from workspace %s/%s (%s), workspace is in Local Execution mode\", remoteWorkspaceName, b.organization, remoteWorkspaceID)\n\t\t} else {\n\t\t\tlog.Printf(\"[TRACE] backend/remote: retrieving variables from workspace %s/%s (%s)\", remoteWorkspaceName, b.organization, remoteWorkspaceID)\n\t\t\ttfeVariables, err := b.client.Variables.ListAll(context.Background(), remoteWorkspaceID, nil)\n\t\t\tif err != nil && err != tfe.ErrResourceNotFound {\n\t\t\t\tdiags = diags.Append(fmt.Errorf(\"error loading variables: %w\", err))\n\t\t\t\treturn nil, nil, diags\n\t\t\t}\n\t\t\tif tfeVariables != nil {\n\t\t\t\tif op.Variables == nil {\n\t\t\t\t\top.Variables = make(map[string]arguments.UnparsedVariableValue)\n\t\t\t\t}\n\t\t\t\tfor _, v := range tfeVariables.Items {\n\t\t\t\t\tif v.Category == tfe.CategoryTerraform {","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/backend/remote/backend_context.go#L90-L126","documentation":"In LocalRun(), b.fetchWorkspace(context.Background(), b.organization, op.Workspace) failed. This second workspace fetch (after getRemoteWorkspaceID) is done specifically to read w.ExecutionMode and decide whether to pull variables. It can return the same 'workspace not found' / 'unexpected error' messages as error 403/404, wrapped here under 'error loading workspace'.","triggerScenarios":"LocalRun() calls fetchWorkspace() to check execution mode; it errors — either tfe.ErrResourceNotFound (wrapped into the 'workspace not found' 403-style message) or any other error (wrapped into the 'unexpected error' 404-style message). Note this uses context.Background(), so context.Canceled won't short-circuit it.","commonSituations":"A workspace that was readable a moment earlier (for getRemoteWorkspaceID) now fails — rare race; more commonly the same misconfiguration as 417 but surfaced at the execution-mode step; token permissions changed between calls.","solutions":["Unwrap the %w to see whether it's the 'workspace not found' (403-shape) or 'unexpected error' (404-shape) message and follow that error's guidance.","Confirm workspace name, org, and token read access are stable.","Retry; transient failures between the two fetches indicate a flaky connection."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Precheck execution-mode fetch once and reuse, avoiding a second failing call.\nw, err := b.fetchWorkspace(ctx, b.organization, op.Workspace)\nif err != nil { return err }","typeGuard":"func isLocalMode(w *tfe.Workspace) bool { return isLocalExecutionMode(w.ExecutionMode) }","tryCatchPattern":"w, err := b.fetchWorkspace(context.Background(), b.organization, op.Workspace)\nif err != nil {\n    return fmt.Errorf(\"error loading workspace: %w\", err)\n}","preventionTips":["Unwrap %w to distinguish 'workspace not found' from 'unexpected error'.","Keep workspace name/org/token stable across the LocalRun sequence.","Retry on transient inter-call failures."],"tags":["workspace","local-run","execution-mode"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}