{"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/c9def3e214014c1188faabfc4a5bde5095139765/internal/backend/remote/backend_state.go#L108-L144","documentation":"Emitted by remoteClient.Put (backend_state.go:124-127) when json.Marshal cannot encode the already-marshaled output-values structure `ov` produced by jsonstate.MarshalOutputs. Since MarshalOutputs is designed to return JSON-serializable data, this is an extremely rare invariant violation — some value inside the structure is not JSON-serializable.","triggerScenarios":"MarshalOutputs returns a structure containing a Go type that json.Marshal cannot serialize (e.g. a channel, func, or unsupported number), which should be impossible given MarshalOutputs' contract but would surface here.","commonSituations":"Effectively unreachable under normal operation; indicates a bug in jsonstate.MarshalOutputs or a corrupted state producing a non-serializable intermediate value. Almost always a code defect rather than a user config issue.","solutions":["Capture the wrapped %s error and the offending state, and file a bug against the jsonstate/state packages.","Re-run the operation; if reproducible, bisect the config/provider producing the offending output value.","As a workaround, simplify or temporarily remove output blocks whose values trigger the failure, then re-apply."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Treat as invariant violation: capture the JSON error and the producing state for diagnostics.\nov, err := jsonstate.MarshalOutputs(stateFile.State.RootOutputValues)\nif err != nil { return err }\no, err := json.Marshal(ov)\nif err != nil {\n    log.Printf(\"[ERROR] non-serializable output structure from MarshalOutputs: %v\", err)\n    return fmt.Errorf(\"error converting output values to json: %s\", err)\n}","preventionTips":["Treat this error as a likely bug in jsonstate — capture the state and file an issue.","Add unit tests around jsonstate output round-trips to catch regressions.","Simplify output blocks to isolate which value breaks serialization.","Do not suppress this error; the stored JSON outputs would be wrong."],"tags":["state","outputs","json","serialization","internal"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}