{"record":{"id":"bc825e1cc64e594e","repo":"hashicorp/terraform","slug":"failed-to-load-state-s","errorCode":null,"errorMessage":"Failed to load state: %s","messagePattern":"Failed to load state: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/meta_backend.go","lineNumber":1493,"sourceCode":"\t\t\"Unable to determine state store init reason\",\n\t\t\"This is a bug in Terraform and should be reported\",\n\t))\n\treturn nil, diags\n}\n\n// backendFromState returns the initialized (not configured) backend directly\n// from the backend state. This should be used only when a user runs\n// `terraform init -backend=false`. This function returns a local backend if\n// there is no backend state or no backend configured.\nfunc (m *Meta) backendFromState(_ context.Context) (backend.Backend, tfdiags.Diagnostics) {\n\tvar diags tfdiags.Diagnostics\n\t// Get the path to where we store a local cache of backend configuration\n\t// if we're using a remote backend. This may not yet exist which means\n\t// we haven't used a non-local backend before. That is okay.\n\tstatePath := filepath.Join(m.DataDir(), DefaultStateFilename)\n\tsMgr := &clistate.LocalState{Path: statePath}\n\tif err := sMgr.RefreshState(); err != nil {\n\t\tdiags = diags.Append(fmt.Errorf(\"Failed to load state: %s\", err))\n\t\treturn nil, diags\n\t}\n\ts := sMgr.State()\n\tif s == nil {\n\t\t// no state, so return a local backend\n\t\tlog.Printf(\"[TRACE] Meta.Backend: backend has not previously been initialized in this working directory\")\n\t\treturn backendLocal.New(), diags\n\t}\n\n\t// Depending on the contents of the backend state file,\n\t// prepare a backend.Backend in the appropriate way.\n\tvar b backend.Backend\n\tswitch {\n\tcase !s.StateStore.Empty():\n\t\t// state_store\n\t\tlog.Printf(\"[TRACE] Meta.Backend: working directory was previously initialized for %q state store\", s.StateStore.Type)\n\t\tvar ssDiags tfdiags.Diagnostics\n\t\tb, ssDiags = m.savedStateStore(sMgr) // Relies on the state manager's internal state being refreshed above.","sourceCodeStart":1475,"sourceCodeEnd":1511,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/meta_backend.go#L1475-L1511","documentation":"Inside Meta.backendFromState (meta_backend.go:1493), which is the path taken only by `terraform init -backend=false`. It calls clistate.LocalState.RefreshState() to read the local backend-state cache file (.terraform/terraform.tfstate); this error fires when that read or JSON parse fails. Terraform needs that file to recover which backend/state-store was previously configured.","triggerScenarios":"Running `terraform init -backend=false` (or any code path using backendFromState) when .terraform/terraform.tfstate is missing, not readable due to file permissions, or contains malformed/truncated JSON.","commonSituations":"A truncated state cache file left by a crashed/killed process, a checkout where .terraform is partially synced, ownership/permission changes on the .terraform directory, or a disk-full event corrupting the file.","solutions":["Check the wrapped `%s` detail: a JSON error means a corrupt file, a permission error means ownership/mode issues.","Delete the offending .terraform/terraform.tfstate (and .terraform.tfstate.backup) and re-run `terraform init -backend=false`.","Restore correct file ownership/permissions on the .terraform directory if the read was denied.","If you need the saved backend info, recover from source control or backup before deleting."],"exampleFix":"// before: terraform init -backend=false  (fails on corrupt .terraform/terraform.tfstate)\n// after: rm -f .terraform/terraform.tfstate* && terraform init -backend=false","handlingStrategy":"validation","validationCode":"// Validate the local state cache file is readable+valid JSON before relying on backendFromState.\nfunc checkLocalStateFile(path string) error {\n    b, err := os.ReadFile(path)\n    if err != nil { return err }\n    var v map[string]any\n    if err := json.Unmarshal(b, &v); err != nil { return fmt.Errorf(\"corrupt %s: %w\", path, err) }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Don't sync/check in a half-written .terraform directory.","Ensure the .terraform directory is writable and owned by the running user.","Run `terraform init -backend=false` only in a properly initialized workdir.","If a process is killed during init, delete .terraform/terraform.tfstate before retrying."],"tags":["backend","init","state","filesystem","json"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}