{"record":{"id":"e156a47f82a31786","repo":"hashicorp/terraform","slug":"couldn-t-read-plan-data-for-cloud-run-s-w","errorCode":null,"errorMessage":"couldn't read plan data for cloud run %s: %w","messagePattern":"couldn't read plan data for cloud run (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cloud/backend_show.go","lineNumber":75,"sourceCode":"\t\t// Bail, we can't use this.\n\t\terr = fmt.Errorf(\"can't display a cloud plan that is currently %s\", r.Plan.Status)\n\t\treturn nil, err\n\t}\n\n\t// Fetch the json plan!\n\tif redacted {\n\t\tjsonBytes, err = readRedactedPlan(ctx, b.client.BaseURL(), b.Token, r.Plan.ID)\n\t} else {\n\t\tjsonBytes, err = b.client.Plans.ReadJSONOutput(ctx, r.Plan.ID)\n\t}\n\tif err == tfe.ErrResourceNotFound {\n\t\tif redacted {\n\t\t\treturn nil, fmt.Errorf(\"couldn't read plan data for cloud run %s; make sure you've run `terraform login` and that you have permission to view the run\", runID)\n\t\t} else {\n\t\t\treturn nil, fmt.Errorf(\"couldn't read unredacted JSON plan data for cloud run %s; make sure you've run `terraform login` and that you have admin permissions on the workspace\", runID)\n\t\t}\n\t} else if err != nil {\n\t\treturn nil, fmt.Errorf(\"couldn't read plan data for cloud run %s: %w\", runID, err)\n\t}\n\n\t// Format a run header and footer\n\theader := strings.TrimSpace(fmt.Sprintf(runHeader, b.Hostname, b.Organization, r.Workspace.Name, r.ID))\n\tfooter := strings.TrimSpace(statusFooter(r.Status, r.Actions.IsConfirmable, r.Workspace.Locked))\n\n\tout := &cloudplan.RemotePlanJSON{\n\t\tJSONBytes: jsonBytes,\n\t\tRedacted:  redacted,\n\t\tMode:      mode,\n\t\tQualities: opts,\n\t\tRunHeader: header,\n\t\tRunFooter: footer,\n\t}\n\n\treturn out, nil\n}\n","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/cloud/backend_show.go#L57-L93","documentation":"Returned by ShowPlanForRun when fetching plan JSON (redacted or unredacted) fails with an error other than tfe.ErrResourceNotFound. The underlying cause is wrapped for diagnostics.","triggerScenarios":"readRedactedPlan or Plans.ReadJSONOutput returns a non-404 failure: 5xx, timeout, context cancellation, streaming/JSON decode error, auth token rejected mid-request.","commonSituations":"Transient API outage, network interruption during the streamed plan JSON read, expired token, or a malformed plan JSON object on the server.","solutions":["Inspect the wrapped %w cause to classify (network vs auth vs server).","Retry with backoff for transient (5xx, timeout) errors.","Re-authenticate if the cause is an auth/permission error (401/403 surfaced as non-404).","Check HCP/TFE status and plan-output endpoint health."],"exampleFix":"// before\nb, err := b.client.Plans.ReadJSONOutput(ctx, planID)\n// after: classify and retry transient, surface persistent\nif err != nil && !errors.Is(err, tfe.ErrResourceNotFound) {\n    if isTransient(err) { return retry() }\n    return fmt.Errorf(\"couldn't read plan data for cloud run %s: %w\", runID, err)\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":"func isTransientPlanReadErr(err error) bool {\n    var netErr net.Error\n    if errors.As(err, &netErr) && netErr.Timeout() { return true }\n    s := err.Error()\n    return strings.Contains(s, \"context deadline\") || strings.Contains(s, \"503\") || strings.Contains(s, \"502\")\n}","tryCatchPattern":"backoff := time.Second\nfor i := 0; i < 3; i++ {\n    jsonBytes, err = read(b, ctx, r.Plan.ID)\n    if err == nil { break }\n    if errors.Is(err, tfe.ErrResourceNotFound) || !isTransientPlanReadErr(err) { break }\n    time.Sleep(backoff); backoff *= 2\n}","preventionTips":["Retry transient plan-output reads with backoff.","Keep context deadlines generous for streamed JSON.","Re-authenticate on persistent auth-class errors."],"tags":["terraform","cloud-backend","network","api-error","show","retry"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}