{"record":{"id":"ad7712d334a68471","repo":"hashicorp/terraform","slug":"backenddiags-err","errorCode":null,"errorMessage":"backendDiags.Err()","messagePattern":"backendDiags\\.Err\\(\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/command/state_meta.go","lineNumber":67,"sourceCode":"\n\t\t// Check remote Terraform version is compatible\n\t\tremoteVersionDiags := c.remoteVersionCheck(b, workspace)\n\t\tc.showDiagnostics(remoteVersionDiags)\n\t\tif remoteVersionDiags.HasErrors() {\n\t\t\treturn nil, fmt.Errorf(\"Error checking remote Terraform version\")\n\t\t}\n\n\t\t// Get the state\n\t\ts, sDiags := b.StateMgr(workspace)\n\t\tif sDiags.HasErrors() {\n\t\t\treturn nil, sDiags.Err()\n\t\t}\n\n\t\t// Get a local backend\n\t\tlocalRaw, backendDiags := c.Backend(&BackendOpts{ForceLocal: true})\n\t\tif backendDiags.HasErrors() {\n\t\t\t// This should never fail\n\t\t\tpanic(backendDiags.Err())\n\t\t}\n\t\tlocalB := localRaw.(*backendLocal.Local)\n\t\t_, stateOutPath, _ = localB.StatePaths(workspace)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\trealState = s\n\t}\n\n\t// We always backup state commands, so set the back if none was specified\n\t// (the default is \"-\", but some tests bypass the flag parsing).\n\tif backupPath == \"-\" || backupPath == \"\" {\n\t\t// Determine the backup path. stateOutPath is set to the resulting\n\t\t// file where state is written (cached in the case of remote state)\n\t\tbackupPath = fmt.Sprintf(\n\t\t\t\"%s.%d%s\",\n\t\t\tstateOutPath,","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/state_meta.go#L49-L85","documentation":"This panic fires in StateMeta when c.Backend(&BackendOpts{ForceLocal: true}) returns diagnostics with errors. The local backend is the built-in fallback that stores state on the local filesystem, so it must always be constructable — an error here means the local backend registry/construction is broken, not a user-config problem.","triggerScenarios":"Any state command (state list/show/mv/rm/push/pull) calling backendsAndState via StateMeta. Fires when the forced-local backend construction itself returns errors, e.g. the local backend schema fails to build, a required plugin for the 'local' backend is missing from the binary, or an internal init path throws.","commonSituations":"A broken Terraform build (local backend not compiled in), an internal refactor that broke backendLocal registration, or a corrupted/missing state directory that the local backend cannot initialize. Extremely rare in released binaries.","solutions":["Run `terraform version` and `terraform init` to confirm the binary is intact; if those also fail, reinstall the Terraform binary from an official release.","Check the workspace: ensure the working directory is writable and the .terraform/ directory is not partially deleted; remove .terraform and re-run `terraform init`.","If building Terraform from source, confirm the build is clean (`go build ./...`) and that backend/local is included.","File a bug with the full stack trace if it reproduces on an official release — this path is documented as must-succeed."],"exampleFix":"// before\nlocalRaw, backendDiags := c.Backend(&BackendOpts{ForceLocal: true})\nif backendDiags.HasErrors() { panic(backendDiags.Err()) }\n// after — surface as a real diagnostic instead of crashing (for maintainers)\nif backendDiags.HasErrors() {\n  diags = diags.Append(tfdiags.Sourceless(tfdiags.Error,\n    \"Failed to initialize local backend\",\n    backendDiags.Err().Error()))\n  return nil, diags\n}","handlingStrategy":"validation","validationCode":"// Before relying on the local backend, probe it explicitly.\nlocalRaw, diags := c.Backend(&BackendOpts{ForceLocal: true})\nif diags.HasErrors() {\n  return nil, fmt.Errorf(\"local backend unavailable: %w\", diags.Err())\n}","typeGuard":"// n/a","tryCatchPattern":null,"preventionTips":["Treat the local backend as a hard dependency in CI: run `terraform init` first to materialize .terraform/.","Pin to an official Terraform release for state commands.","If building from source, ensure `go build ./...` is clean before running state subcommands."],"tags":["terraform-cli","backend","state","panic","invariant","local-backend"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}