{"record":{"id":"10b15613f6561f81","repo":"opentofu/opentofu","slug":"error-marshaling-config-w","errorCode":null,"errorMessage":"error marshaling config: %w","messagePattern":"error marshaling config: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/jsonplan/plan.go","lineNumber":308,"sourceCode":"\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: %w\", 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: %w\", err)\n\t}\n\n\treturn output, nil\n}\n\n// Marshal returns the json encoding of a tofu plan.\nfunc Marshal(\n\tconfig *configs.Config,\n\tp *plans.Plan,\n\tsf *statefile.File,\n\tschemas *tofu.Schemas,\n) ([]byte, error) {\n\toutput, err := MarshalForLog(config, p, sf, schemas)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn json.Marshal(output)","sourceCodeStart":290,"sourceCodeEnd":326,"githubUrl":"https://github.com/opentofu/opentofu/blob/3561785c48c1ce615e7c50261bd351f26053efa2/internal/command/jsonplan/plan.go#L290-L326","documentation":"Final stage wrapper: jsonconfig.Marshal failed while embedding the configuration view into the JSON plan. The inner error is one of the config-marshal failures - type-constraint marshaling (unreachable-by-design), unsupported resource mode, or 'no schema found' for a configured resource.","triggerScenarios":"Any jsonconfig failure over the plan's config: missing provider schema for a configured resource type, unknown resource mode from version skew, or a type constraint that fails cty JSON serialization.","commonSituations":"'tofu show -json' on plans/configs from other environments or versions; providers not initialized in the reading environment.","solutions":["Unwrap the error to see which config-marshal failure occurred","If 'no schema found': run 'tofu init' and regenerate the plan","Otherwise align OpenTofu versions between producer and consumer","Report internal-bug cases with the unwrapped message"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if _, err := jsonplan.Marshal(config, plan, sf, schemas); err != nil {\n    if strings.Contains(err.Error(), \"marshaling config\") {\n        // delegate to the jsonconfig failure family: schema miss -> tofu init; mode/type errors -> version realignment\n    }\n    return err\n}","preventionTips":["Unwrap past the stage wrapper to the jsonconfig cause before acting","Initialize providers in the reading environment","Align versions and regenerate plans rather than patching artifacts"],"tags":["go","json","plan","config","error-wrapping"],"backgroundTag":null,"analyzedSha":"3561785c48c1ce615e7c50261bd351f26053efa2","analyzedAt":"2026-08-15T23:27:16.226Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}