{"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/c9def3e214014c1188faabfc4a5bde5095139765/internal/cloud/state.go#L649-L683","documentation":"tfeOutputToCtyValue first re-marshals output.DetailedType to JSON via json.Marshal. This wraps a failure of that marshal, which is extremely rare since DetailedType is normally a plain JSON-shaped value coming straight from the API.","triggerScenarios":"output.DetailedType contains a non-JSON-encodable Go value, essentially an internal or protocol-level bug or a malformed API response.","commonSituations":"Almost never seen in normal use; indicates a go-tfe or TFE protocol regression producing an invalid DetailedType.","solutions":["Retry; could be a transient malformed response.","Upgrade go-tfe and Terraform to the latest release.","If reproducible, report it with the output ID and state version."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"outs, err := state.GetRootOutputValues(ctx)\nif err != nil && strings.Contains(err.Error(), \"could not marshal output\") {\n    // internal/protocol-level; retry once, then upgrade TF/go-tfe and report if persistent\n}","preventionTips":["Keep Terraform and go-tfe up to date","Retry on a one-off malformed response","Report reproducible cases with the output ID"],"tags":["serialization","outputs","type","json","internal"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}