{"record":{"id":"40e37df62982bcba","repo":"hashicorp/terraform","slug":"failed-to-translate-outputs-w","errorCode":null,"errorMessage":"failed to translate outputs: %w","messagePattern":"failed to translate outputs: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cloud/state.go","lineNumber":224,"sourceCode":"\t\treturn err\n\t}\n\n\tvar jsonState []byte\n\tif schemas != nil {\n\t\tjsonState, err = jsonstate.Marshal(f, schemas)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\tstateFile, err := statefile.Read(bytes.NewReader(buf.Bytes()))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to read state: %w\", err)\n\t}\n\n\tov, err := jsonstate.MarshalOutputs(stateFile.State.RootOutputValues)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to translate outputs: %w\", err)\n\t}\n\tjsonStateOutputs, err := json.Marshal(ov)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to marshal outputs to json: %w\", err)\n\t}\n\n\terr = s.uploadState(s.lineage, s.serial, s.forcePush, buf.Bytes(), jsonState, jsonStateOutputs)\n\tif err != nil {\n\t\ts.stateUploadErr = true\n\t\treturn fmt.Errorf(\"error uploading state: %w\", err)\n\t}\n\t// After we've successfully persisted, what we just wrote is our new\n\t// reference state until someone calls RefreshState again.\n\t// We've potentially overwritten (via force) the state, lineage\n\t// and / or serial (and serial was incremented) so we copy over all\n\t// three fields so everything matches the new state and a subsequent\n\t// operation would correctly detect no changes to the lineage, serial or state.\n\ts.readState = s.state.DeepCopy()","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/cloud/state.go#L206-L242","documentation":"Returned by the state persister when jsonstate.MarshalOutputs(stateFile.State.RootOutputValues) fails while building the JSON representation of state outputs. The %w wraps the marshaling error (e.g. an output value of a type the JSON encoder cannot represent).","triggerScenarios":"After re-reading the serialized state, translating its root output values into the JSON state format fails — typically an output whose cty type cannot be marshaled to JSON (e.g. contains non-string map keys, unsupported nested types), or a schema/type mismatch.","commonSituations":"Outputs producing unusual cty values (sets/maps of objects, dynamic types), provider output bugs surfacing unusual types, or a state produced by a mismatched Terraform/provider version being re-persisted.","solutions":["Inspect the wrapped error to see which output value failed to marshal.","Simplify or correct the offending output declaration (ensure JSON-serializable types).","Upgrade the provider/Terraform to resolve known output-type marshaling bugs.","As a last resort, run `terraform refresh`/`terraform state push` after correcting outputs."],"exampleFix":"// before\noutput \"roles\" { value = nonsensitive({ (rand) = ... }) } // non-string keys -> marshal error\n// after: use string keys and JSON-friendly structure\noutput \"roles\" { value = { for k, v in local.roles : tostring(k) => v } }","handlingStrategy":"validation","validationCode":"// Validate outputs are JSON-serializable before persisting.\nfor name, ov := range state.RootOutputValues {\n    if !jsonSerializable(ov.Value) {\n        return fmt.Errorf(\"output %q is not JSON-serializable\", name)\n    }\n}","typeGuard":"func jsonSerializable(v cty.Value) bool {\n    _, err := json.Marshal(ctyjson.SimpleJSONValue{Value: v})\n    return err == nil\n}","tryCatchPattern":"ov, err := jsonstate.MarshalOutputs(stateFile.State.RootOutputValues)\nif err != nil {\n    // inspect which output failed; correct the config and re-persist\n    return fmt.Errorf(\"failed to translate outputs: %w\", err)\n}","preventionTips":["Keep outputs JSON-friendly (string keys, supported types).","Add output-type tests in modules that emit complex values.","Upgrade providers/Terraform to fix known output marshaling bugs."],"tags":["terraform","cloud-backend","state","outputs","json","marshaling"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}