{"record":{"id":"d9ef45640d70f267","repo":"hashicorp/terraform","slug":"error-converting-output-values-to-json-s","errorCode":null,"errorMessage":"error converting output values to json: %s","messagePattern":"error converting output values to json: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/backend/remote/backend_state.go","lineNumber":126,"sourceCode":"\n// Put the remote state.\nfunc (r *remoteClient) Put(state []byte) tfdiags.Diagnostics {\n\tvar diags tfdiags.Diagnostics\n\tctx := context.Background()\n\n\t// Read the raw state into a Terraform state.\n\tstateFile, err := statefile.Read(bytes.NewReader(state))\n\tif err != nil {\n\t\treturn diags.Append(fmt.Errorf(\"error reading state: %s\", err))\n\t}\n\n\tov, err := jsonstate.MarshalOutputs(stateFile.State.RootOutputValues)\n\tif err != nil {\n\t\treturn diags.Append(fmt.Errorf(\"error reading output values: %s\", err))\n\t}\n\to, err := json.Marshal(ov)\n\tif err != nil {\n\t\treturn diags.Append(fmt.Errorf(\"error converting output values to json: %s\", err))\n\t}\n\n\toptions := tfe.StateVersionUploadOptions{\n\t\tStateVersionCreateOptions: tfe.StateVersionCreateOptions{\n\t\t\tLineage:          tfe.String(stateFile.Lineage),\n\t\t\tSerial:           tfe.Int64(int64(stateFile.Serial)),\n\t\t\tMD5:              tfe.String(fmt.Sprintf(\"%x\", md5.Sum(state))),\n\t\t\tForce:            tfe.Bool(r.forcePush),\n\t\t\tJSONStateOutputs: tfe.String(base64.StdEncoding.EncodeToString(o)),\n\t\t},\n\t\tRawState: state,\n\t}\n\n\t// If we have a run ID, make sure to add it to the options\n\t// so the state will be properly associated with the run.\n\tif r.runID != \"\" {\n\t\toptions.Run = &tfe.Run{ID: r.runID}\n\t}","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/backend/remote/backend_state.go#L108-L144","documentation":"Standard json.Marshal over the object produced by jsonstate.MarshalOutputs. Under normal operation this cannot fail (cty-derived maps marshal cleanly), so reaching it indicates an unexpected, non-JSON-encodable value slipped into the output map.","triggerScenarios":"json.Marshal returns an error: a channel/func/unsupported type ended up in the marshaled map, a recursive structure, or an encoding error from a malformed cty value conversion. Practically unreachable.","commonSituations":"Forked jsonstate returning non-canonical types; bug in output-value sensitive-marking handling producing an unencodable wrapper; memory corruption.","solutions":["Treat as an internal bug — capture the wrapped error and the offending output set, then file an issue.","Pin to a known-good Terraform release if it appeared after an upgrade.","Temporarily remove the most recently added output to confirm which value triggers it."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// json.Marshal over a cty-derived map should not fail; treat as fatal-but-contained\no, err := json.Marshal(ov)\nif err != nil {\n    return fmt.Errorf(\"internal: outputs unencodable (%w); see issue tracker\", err)\n}","preventionTips":["Treat as an internal invariant violation — capture and file a bug.","Pin Terraform core to a release where outputs marshal reliably.","Reduce output surface to isolate which value is unencodable."],"tags":["terraform","remote-backend","state","outputs","json","internal"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}