{"record":{"id":"8f6e7adefde9c5ae","repo":"hashicorp/terraform","slug":"could-not-marshal-output-s-type-w","errorCode":null,"errorMessage":"could not marshal output %s type: %w","messagePattern":"could not marshal output (.+?) type: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cloud/state.go","lineNumber":667,"sourceCode":"\t\t// If the header field is either absent or invalid then we'll\n\t\t// just choose zero, which effectively means that we'll just use\n\t\t// the caller's requested interval instead. If the caller has no\n\t\t// requested interval or it is zero, then we will disable snapshots.\n\t\ts.stateSnapshotInterval = time.Duration(0)\n\t}\n\n\t// We will only enable snapshots for intervals greater than zero\n\tlog.Printf(\"[TRACE] Intermediate state interval is set by header to %v\", s.stateSnapshotInterval)\n\ts.enableIntermediateSnapshots = s.stateSnapshotInterval > 0\n}\n\n// tfeOutputToCtyValue decodes a combination of TFE output value and detailed-type to create a\n// cty value that is suitable for use in terraform.\nfunc tfeOutputToCtyValue(output tfe.StateVersionOutput) (cty.Value, error) {\n\tvar result cty.Value\n\tbufType, err := json.Marshal(output.DetailedType)\n\tif err != nil {\n\t\treturn result, fmt.Errorf(\"could not marshal output %s type: %w\", output.ID, err)\n\t}\n\n\tvar ctype cty.Type\n\terr = ctype.UnmarshalJSON(bufType)\n\tif err != nil {\n\t\treturn result, fmt.Errorf(\"could not interpret output %s type: %w\", output.ID, err)\n\t}\n\n\tresult, err = gocty.ToCtyValue(output.Value, ctype)\n\tif err != nil {\n\t\treturn result, fmt.Errorf(\"could not interpret value %v as type %s for output %s: %w\", result, ctype.FriendlyName(), output.ID, err)\n\t}\n\n\treturn result, nil\n}\n","sourceCodeStart":649,"sourceCodeEnd":683,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/cloud/state.go#L649-L683","documentation":"Thrown inside tfeOutputToCtyValue when Go's json.Marshal fails to serialize the output's DetailedType field. DetailedType is an interface{} holding the type description from TFE; if it contains a Go value json.Marshal cannot handle, this error fires. The %w wraps the json.Marshal error and includes the output ID.","triggerScenarios":"The TFE API returned a DetailedType containing an unserializable Go value (e.g. a map with non-string keys, a func, or a circular reference); a go-tfe client version deserialized the type into an unexpected Go type; corrupt type data in the state version output.","commonSituations":"Version mismatch between the go-tfe client embedded in terraform and the TFE server API producing the DetailedType; a new output type added server-side not yet understood by the client; very rare in stable releases.","solutions":["Upgrade terraform to the latest release to get a compatible go-tfe client","Enable TF_LOG=TRACE to inspect the raw DetailedType value before marshaling","Remove the problematic output from configuration and re-apply to rewrite the state version output","Report the issue with the output ID and terraform/TFE versions"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Validate that the DetailedType is JSON-serializable before conversion\n// (requires access to the tfe.StateVersionOutput before calling tfeOutputToCtyValue):\nfor _, output := range outputs.Items {\n    if _, err := json.Marshal(output.DetailedType); err != nil {\n        log.Printf(\"[WARN] output %s has non-serializable DetailedType: %v\", output.ID, err)\n    }\n}","typeGuard":null,"tryCatchPattern":"// This error originates inside tfeOutputToCtyValue which is called by GetRootOutputValues.\n// Catch at the GetRootOutputValues call boundary:\n_, err := state.GetRootOutputValues(ctx)\nif err != nil && strings.Contains(err.Error(), \"could not marshal output\") {\n    // DetailedType from TFE is unserializable — likely a client/server version mismatch\n    return fmt.Errorf(\"upgrade terraform to match the TFE server version: %w\", err)\n}","preventionTips":["Keep terraform CLI and TFE/HCP Terraform on compatible, current versions","Report persistent DetailedType marshal failures with the output ID and versions","After TFE server upgrades, test output reads before resuming production operations"],"tags":["outputs","cty","json","type-decoding","tfe","terraform"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}