{"record":{"id":"0fb0636b88aec5b3","repo":"hashicorp/terraform","slug":"errstatestoreinitdiag-requires-a-non-nil-reason-ar","errorCode":null,"errorMessage":"errStateStoreInitDiag requires a non-nil reason argument","messagePattern":"errStateStoreInitDiag requires a non-nil reason argument","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/command/meta_backend_errors.go","lineNumber":203,"sourceCode":"\treturn tfdiags.Sourceless(\n\t\ttfdiags.Error,\n\t\t\"Backend initialization required, please run \\\"terraform state migrate\\\" or \\\"terraform init -reconfigure\\\"\",\n\t\tmsg,\n\t)\n}\n\ntype ssInitReason struct {\n\tMigrationNeeded bool\n\tReason          string\n\tSubject         *hcl.Range\n}\n\n// errStateStoreInitDiag creates a diagnostic to present to users when\n// users attempt to run a non-init command after making a change to their\n// state_store configuration.\nfunc errStateStoreInitDiag(ir *ssInitReason) tfdiags.Diagnostics {\n\tif ir == nil {\n\t\tpanic(\"errStateStoreInitDiag requires a non-nil reason argument\")\n\t}\n\n\tvar msg string\n\tmsg += fmt.Sprintf(\"Reason: %s\\n\\n\", ir.Reason)\n\n\tmsg += `A \"state store\" is an interface that Terraform uses to store state.\nChanges to state store configurations require reinitialization, and a\ndecision whether to migrate any existing state or not.\n\nIf you want to migrate existing state using the current configuration,\nplease run \"terraform state migrate\".\n\nIf you don't want to migrate existing state and just reconfigure how state is\nstored using the current configuration, please run \"terraform init -reconfigure\".\n\nIf the change reason above is incorrect, please verify your configuration\nhasn't changed and try again. At this point, no changes to your existing\nconfiguration or state have been made.`","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/meta_backend_errors.go#L185-L221","documentation":"Programmer-error panic in errStateStoreInitDiag: the helper requires a non-nil *ssInitReason, because it dereferences ir.Reason and ir.Subject. Passing nil is a coding mistake in internal callers, not a user input error.","triggerScenarios":"Internal code calling errStateStoreInitDiag(nil) instead of building an ssInitReason struct; typically after a refactor or in a new code path that detects a state-store init reason but forgot to populate the struct.","commonSituations":"Internal Terraform bug; custom command wrappers that invoke errStateStoreInitDiag directly with nil.","solutions":["Report as a Terraform bug with the command/config that triggered it.","If you call this helper internally, always construct a populated ssInitReason (MigrationNeeded, Reason, Subject) before invoking."],"exampleFix":"// before\ndiags := errStateStoreInitDiag(nil)\n\n// after\nreason := &ssInitReason{Reason: \"state_store changed\", Subject: r}\ndiags := errStateStoreInitDiag(reason)","handlingStrategy":"validation","validationCode":"if ir == nil {\n    return tfdiags.Diagnostics{}.Append(tfdiags.Sourceless(tfdiags.Error, \"missing state-store init reason\", \"...\"))\n}\nreturn errStateStoreInitDiag(ir)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always construct a populated *ssInitReason before calling errStateStoreInitDiag.","Treat this as an internal coding error if it surfaces.","Add a unit test that asserts callers never pass nil."],"tags":["terraform","state-store","panic","internal-bug","nil-check"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}