{"record":{"id":"02b73e467421cc09","repo":"hashicorp/terraform","slug":"error-marshaling-prior-state-s","errorCode":null,"errorMessage":"error marshaling prior state: %s","messagePattern":"error marshaling prior state: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/jsonplan/plan.go","lineNumber":337,"sourceCode":"\t\t\treturn nil, fmt.Errorf(\"error in marshaling deferred action invocations: %s\", err)\n\t\t}\n\t}\n\n\t// output.OutputChanges\n\tif output.OutputChanges, err = MarshalOutputChanges(p.Changes); err != nil {\n\t\treturn nil, fmt.Errorf(\"error in marshaling output changes: %s\", err)\n\t}\n\n\t// output.Checks\n\tif p.Checks != nil && p.Checks.ConfigResults.Len() > 0 {\n\t\toutput.Checks = jsonchecks.MarshalCheckStates(p.Checks)\n\t}\n\n\t// output.PriorState\n\tif sf != nil && !sf.State.Empty() {\n\t\toutput.PriorState, err = jsonstate.Marshal(sf, schemas)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error marshaling prior state: %s\", err)\n\t\t}\n\t}\n\n\t// output.Config\n\toutput.Config, err = jsonconfig.Marshal(config, schemas)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error marshaling config: %s\", err)\n\t}\n\n\t// output.Changes.ActionInvocations\n\tif p.Changes.ActionInvocations != nil {\n\t\tif output.ActionInvocations, err = MarshalActionInvocations(p.Changes.ActionInvocations, schemas); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error marshaling action invocations: %s\", err)\n\t\t}\n\t}\n\n\treturn json.Marshal(output)\n}","sourceCodeStart":319,"sourceCodeEnd":355,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/jsonplan/plan.go#L319-L355","documentation":"Top-level propagation error from Marshal: jsonstate.Marshal failed while rendering the prior state file embedded in the plan JSON. The wrapped error comes from the state marshaller and usually indicates a schema or decode problem with prior-state resources.","triggerScenarios":"A resource in prior state references a provider schema missing at render time, or its value cannot be decoded/marshaled against the current schema.","commonSituations":"State written by an older Terraform/provider being rendered by a newer one with incompatible schemas; provider removed from config but still referenced in state.","solutions":["Read the wrapped error for the failing state resource.","Ensure all providers for resources present in state are initialized.","Run `terraform refresh`/`state upgrade` if the state format is from an older version.","Regenerate the plan after aligning versions."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Ensure every resource present in prior state has a schema before marshaling.\nfunc stateSchemasOk(sf *statefile.File, schemas *terraform.Schemas) error {\n    if sf == nil { return nil }\n    for _, m := range sf.State.Modules {\n        for _, r := range m.Resources {\n            for _, i := range r.Instances {\n                _ = i\n                // look up ResourceTypeConfig by provider/mode/type; error if Body == nil\n            }\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run `terraform state upgrade`/refresh when moving across major versions.","Keep providers for all in-state resources initialized even after config removal."],"tags":["go","terraform","plan","prior-state","state","error-wrapping","jsonplan"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}