{"record":{"id":"60c5d749a1c39ece","repo":"hashicorp/terraform","slug":"failed-to-load-state-manager-w","errorCode":null,"errorMessage":"Failed to load state manager: %w","messagePattern":"Failed to load state manager: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/show.go","lineNumber":402,"sourceCode":"\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"Error loading statefile: %w\", err)\n\t}\n\tdefer file.Close()\n\n\tvar stateFile *statefile.File\n\tstateFile, err = statefile.Read(file)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"Error reading %s as a statefile: %w\", path, err)\n\t}\n\treturn stateFile, nil\n}\n\n// getStateFromBackend returns the State for the current workspace, if available.\nfunc getStateFromBackend(b backend.Backend, workspace string) (*statefile.File, error) {\n\t// Get the state store for the given workspace\n\tstateStore, sDiags := b.StateMgr(workspace)\n\tif sDiags.HasErrors() {\n\t\treturn nil, fmt.Errorf(\"Failed to load state manager: %w\", sDiags.Err())\n\t}\n\n\t// Refresh the state store with the latest state snapshot from persistent storage\n\tif err := stateStore.RefreshState(); err != nil {\n\t\treturn nil, fmt.Errorf(\"Failed to load state: %w\", err)\n\t}\n\n\t// Get the latest state snapshot and return it\n\tstateFile := statemgr.Export(stateStore)\n\treturn stateFile, nil\n}\n","sourceCodeStart":384,"sourceCodeEnd":414,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/show.go#L384-L414","documentation":"Wrapped error from getStateFromBackend when b.StateMgr(workspace) returns diagnostics with errors. This builds the state manager for the resolved workspace against the configured backend; diagnostic errors mean the backend could not initialize its state store (e.g. S3 bucket absent, cloud auth failed, local state path unwritable). 'terraform show' (no path) then has no state to display.","triggerScenarios":"Running 'terraform show' with no path when the backend fails to construct a state manager for the current workspace — missing bucket/object, invalid credentials, non-existent cloud workspace, or local state file I/O error.","commonSituations":"Backend credentials expired; S3 state object/bucket deleted; cloud workspace renamed/deleted; local state file locked or permission denied; region/endpoint misconfiguration; backend not yet initialized ('terraform init' not run).","solutions":["Run 'terraform init' to reconfigure the backend and surface auth/config errors.","Verify the state resource (bucket, object key, cloud workspace) exists for the configured backend.","Confirm credentials (AWS_*, TF_TOKEN_*, TF_CLOUD_*) are valid and have access.","Check the wrapped diagnostic for the backend-specific cause."],"exampleFix":"// before\n$ terraform show\nFailed to load state manager: ...\n// after\n$ terraform init\n$ terraform show","handlingStrategy":"validation","validationCode":"// Pre-flight: confirm backend resource reachability before 'terraform show' (no path)\npackage main\n\n// (S3 illustration) confirm the state object exists\nfunc preflightStateObject(bucket, key, region string) error {\n\tsess := session.Must(session.NewSession(&aws.Config{Region: &region}))\n\t_, err := s3.New(sess).HeadObject(&s3.HeadObjectInput{Bucket: &bucket, Key: &key})\n\tif err != nil { return fmt.Errorf(\"state object unreachable: %w\", err) }\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run 'terraform init' to validate backend config and credentials.","Keep backend credentials current with read access to the state object/workspace.","Confirm the workspace name exists on cloud backends."],"tags":["show","state","backend","state-manager"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}