{"record":{"id":"2d355a6f0899493c","repo":"pulumi/pulumi","slug":"failed-to-get-logs-w","errorCode":null,"errorMessage":"failed to get logs: %w","messagePattern":"failed to get logs: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/cmd/pulumi/logs/logs.go","lineNumber":137,"sourceCode":"\t\t\t\t\ts.Ref().String(),\n\t\t\t\t\tcmd.FormatTime(*startTime),\n\t\t\t\t)\n\t\t\t}\n\n\t\t\t// IDEA: This map will grow forever as new log entries are found.  We may need to do a more approximate\n\t\t\t// approach here to ensure we don't grow memory unboundedly while following logs.\n\t\t\t//\n\t\t\t// Note: Just tracking latest log date is not sufficient - as stale logs may show up which should have been\n\t\t\t// displayed before previously rendered log entries, but weren't available at the time, so still need to be\n\t\t\t// rendered now even though they are technically out of order.\n\t\t\tshown := map[operations.LogEntry]bool{}\n\t\t\tfor {\n\t\t\t\tlogs, err := backend.GetStackLogs(ctx, secrets.DefaultProvider, s, cfg, operations.LogQuery{\n\t\t\t\t\tStartTime:      startTime,\n\t\t\t\t\tResourceFilter: resourceFilter,\n\t\t\t\t})\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"failed to get logs: %w\", err)\n\t\t\t\t}\n\n\t\t\t\t// When we are emitting a fixed number of log entries, and outputting JSON, wrap them in an array.\n\t\t\t\tif !follow && jsonOut {\n\t\t\t\t\tentries := slice.Prealloc[logEntryJSON](len(logs))\n\n\t\t\t\t\tfor _, logEntry := range logs {\n\t\t\t\t\t\tif _, shownAlready := shown[logEntry]; !shownAlready {\n\t\t\t\t\t\t\teventTime := time.Unix(0, logEntry.Timestamp*1000000)\n\n\t\t\t\t\t\t\tentries = append(entries, logEntryJSON{\n\t\t\t\t\t\t\t\tID:        logEntry.ID,\n\t\t\t\t\t\t\t\tTimestamp: cmd.FormatTime(eventTime.UTC()),\n\t\t\t\t\t\t\t\tMessage:   logEntry.Message,\n\t\t\t\t\t\t\t})\n\n\t\t\t\t\t\t\tshown[logEntry] = true\n\t\t\t\t\t\t}","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/pulumi/pulumi/blob/793f7b2e160db4321fb7fb6b0607461e01cb251e/pkg/cmd/pulumi/logs/logs.go#L119-L155","documentation":"Wraps any error from backend.GetStackLogs, which queries the backend/engine for the stack's operation logs via operations.LogQuery (start time, resource filter). Failures include backend communication errors, the stack's operation log being missing or unreadable, or decryption failures on log entries.","triggerScenarios":"Running `pulumi logs` (with --follow or one-shot) when the backend (cloud or local) fails to return logs: no operations log exists for the stack, network/API errors to the service, or the LogQuery can't be served for the resource filter given via --resource.","commonSituations":"Querying logs for a stack never deployed (no update records); offline use of a cloud backend; --resource ARN/URN typo; expired cloud credentials; secrets provider failing while decrypting log values.","solutions":["Deploy the stack at least once (`pulumi up`) so an operations log exists.","Check backend connectivity and credentials (`pulumi whoami`, re-run `pulumi login`).","Verify the --resource value matches a real resource URN from the stack.","Retry if the wrapped cause indicates a transient network/API error.","Inspect the wrapped error for decryption issues and fix the secrets provider."],"exampleFix":"// before\npulumi logs --stack dev   # backend unreachable\n// after\npulumi logout && pulumi login\npulumi logs --stack dev","handlingStrategy":"retry","validationCode":"// Shell: ensure backend auth and stack has updates before fetching logs\npulumi whoami >/dev/null || { echo \"not logged in\" >&2; exit 1; }\npulumi stack history --stack \"$STACK\" | grep -q . || { echo \"no deployments yet\" >&2; exit 1; }","typeGuard":null,"tryCatchPattern":"// Retry transient backend failures with backoff\nfor i in 1 2 3; do\n  out, err := exec.Command(\"pulumi\", \"logs\", \"--stack\", stack).CombinedOutput()\n  if err == nil { break }\n  if !strings.Contains(string(out), \"failed to get logs\") { log.Fatal(string(out)) }\n  time.Sleep(time.Duration(i) * 2 * time.Second)\n}","preventionTips":["Deploy at least once (`pulumi up`) before expecting logs.","Keep backend credentials fresh (re-run `pulumi login`).","Validate --resource against actual resource URNs (`pulumi stack export`).","Retry on transient network errors; check service status for outages."],"tags":["cli","backend","logs","network"],"backgroundTag":"stack-log-fetch-failed","analyzedSha":"793f7b2e160db4321fb7fb6b0607461e01cb251e","analyzedAt":"2026-08-31T09:36:43.099Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}