{"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":"exception","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/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/meta_backend.go#L1475-L1511","documentation":"In Meta.backendFromState (used only for `terraform init -backend=false`), RefreshState on the local backend-cache file failed. Unlike 661 this path returns a local backend when the file is absent (nil state is fine), so this error specifically means the file exists but cannot be read/parsed.","triggerScenarios":"sMgr.RefreshState() errors on the existing .terraform/terraform.tfstate during a -backend=false run. Triggers: corrupt JSON in the cache file, truncated write, permission denied, or an incompatible/unknown state snapshot version that the parser rejects.","commonSituations":"Running `tofu init -backend=false` (or any command forcing local backend) against a working dir whose cache file was corrupted by a crash, manual edit, or a different CLI version; read-only mount of .terraform; file owned by another user.","solutions":["Read the inner %s for the parse/IO cause.","Validate .terraform/terraform.tfstate is well-formed JSON; if corrupt, back it up, delete it, and re-init.","Correct ownership/permissions on .terraform so the current user can read it.","Re-run `tofu init -backend=false` after cleanup; a missing file is acceptable and yields a fresh local backend."],"exampleFix":"// before\ntofu init -backend=false  # .terraform/terraform.tfstate corrupt\n# -> Failed to load state\n\n// after\nrm .terraform/terraform.tfstate\ntofu init -backend=false","handlingStrategy":"validation","validationCode":"// Pre-validate the cache file before a -backend=false run.\nfunc validateBackendCacheReadable(dataDir string) error {\n    p := filepath.Join(dataDir, DefaultStateFilename)\n    if _, err := os.Stat(p); errors.Is(err, os.ErrNotExist) { return nil }\n    b, err := os.ReadFile(p)\n    if err != nil { return err }\n    var raw json.RawMessage\n    return json.Unmarshal(b, &raw)\n}","typeGuard":null,"tryCatchPattern":"if err := sMgr.RefreshState(); err != nil {\n    if errors.Is(err, os.ErrNotExist) {\n        // nil state is fine for backendFromState\n    } else {\n        diags = diags.Append(fmt.Errorf(\"Failed to load state (cache unreadable; run 'tofu init -reconfigure'): %s\", err))\n        return nil, diags\n    }\n}","preventionTips":["For -backend=false runs, ensure .terraform/terraform.tfstate is either absent or valid.","Do not switch users between init and -backend=false commands.","Keep .terraform on a reliable local filesystem."],"tags":["backend","local-state","cache-file","filesystem","backend-false"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}