{"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/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/cloud/state.go#L206-L242","documentation":"Thrown during PersistState when jsonstate.MarshalOutputs fails to translate the state's RootOutputValues into a JSON-serializable structure. This conversion step walks each output value's cty type and builds a JSON representations; it fails when an output value uses a type or nesting depth the marshaler cannot handle. The %w preserves the marshaler's underlying error.","triggerScenarios":"A root output value has a cty type (e.g. deeply nested object, dynamic/pseudo-type, or null with missing type info) that jsonstate.MarshalOutputs cannot encode; state corrupted by a provider returning an unencodable output type; a terraform version where output type tracking is incomplete.","commonSituations":"After upgrading a provider that changed an output's type to a complex nested shape; when outputs reference resources whose schema changed between terraform versions; large configurations with many interconnected outputs after a schema-breaking provider update.","solutions":["Identify which output value triggers the failure by checking the wrapped error message for type information","Temporarily remove or simplify the problematic output (e.g. flatten a deeply nested object) and re-run apply","Upgrade terraform to the latest patch release to pick up fixes to jsonstate output marshaling","If the output type originates from a provider, upgrade or pin the provider to a version whose output schema is compatible with your terraform version"],"exampleFix":"// before\noutput \"raw_config\" {\n  value = some_resource.this  // full resource object, complex type\n}\n// after\noutput \"raw_config\" {\n  value = some_resource.this.id  // simple string\n}","handlingStrategy":"validation","validationCode":"// Before persisting, verify all root outputs can be marshaled:\nfor name, ov := range state.RootOutputValues {\n    if ov == nil || ov.Value.IsNull() {\n        continue\n    }\n    // attempt a cty walk to detect unsupported types early\n    if !ov.Value.Type().IsObjectType() && !ov.Value.Type().IsPrimitiveType() && !ov.Value.Type().IsListType() && !ov.Value.Type().IsMapType() {\n        log.Printf(\"[WARN] output %s has potentially unserializable type %s\", name, ov.Value.Type().FriendlyName())\n    }\n}","typeGuard":null,"tryCatchPattern":"err := stateMgr.PersistState(schemas)\nif err != nil && strings.Contains(err.Error(), \"failed to translate outputs\") {\n    // identify and simplify the offending output, then retry\n    log.Print(\"output translation failed; simplify root outputs and retry\")\n}\nreturn err","preventionTips":["Keep root outputs simple (primitives, flat lists/maps) to avoid type-marshaling edge cases","Avoid exposing entire resource objects as outputs; extract specific attributes","Test output types after provider upgrades before applying to production cloud workspaces"],"tags":["serialization","outputs","state-persist","cty","terraform"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}