-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix: preserve error details in task logs #1987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,9 +18,48 @@ | |
| import { writeFileSync, readFileSync, existsSync, mkdirSync, renameSync } from 'node:fs'; | ||
| import { join, dirname } from 'node:path'; | ||
| import type { TaskLogs, TaskLogPhase, TaskLogPhaseStatus, TaskLogEntry, TaskLogEntryType } from '../../../shared/types'; | ||
| import type { StreamEvent } from '../session/types'; | ||
| import type { StreamEvent, SessionError } from '../session/types'; | ||
| import type { Phase } from '../config/types'; | ||
|
|
||
| // ============================================================================= | ||
| // Error formatting | ||
| // ============================================================================= | ||
|
|
||
| function sanitizeErrorMessage(message: string): string { | ||
| return message | ||
| .replace(/sk-[a-zA-Z0-9-_]{20,}/g, 'sk-***') | ||
| .replace(/Bearer [a-zA-Z0-9\-_.+/=]+/gi, 'Bearer ***') | ||
| .replace(/token[=:]\s*[a-zA-Z0-9\-_.+/=]+/gi, 'token=***'); | ||
| } | ||
|
|
||
| function extractErrorMessage(error: SessionError): string { | ||
| const direct = error?.message?.trim(); | ||
| if (direct) return sanitizeErrorMessage(direct); | ||
|
|
||
| const cause = error?.cause as unknown; | ||
| if (cause instanceof Error && cause.message?.trim()) { | ||
| return sanitizeErrorMessage(cause.message); | ||
| } | ||
|
|
||
| if (typeof cause === 'string' && cause.trim()) { | ||
| return sanitizeErrorMessage(cause); | ||
| } | ||
|
|
||
| if (cause && typeof cause === 'object') { | ||
| const maybeMessage = (cause as { message?: unknown }).message; | ||
| if (typeof maybeMessage === 'string' && maybeMessage.trim()) { | ||
| return sanitizeErrorMessage(maybeMessage); | ||
| } | ||
| const maybeError = (cause as { error?: unknown }).error; | ||
| if (typeof maybeError === 'string' && maybeError.trim()) { | ||
| return sanitizeErrorMessage(maybeError); | ||
| } | ||
| } | ||
|
|
||
| if (error?.code) return `Error: ${error.code}`; | ||
| return 'Unknown error'; | ||
| } | ||
|
Comment on lines
+35
to
+61
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Add focused regression tests for extraction and redaction branches. Given this is a bug fix for lost diagnostics, please add tests for blank 🤖 Prompt for AI Agents |
||
|
|
||
| // ============================================================================= | ||
| // Phase Mapping | ||
| // ============================================================================= | ||
|
|
@@ -147,7 +186,7 @@ export class TaskLogWriter { | |
|
|
||
| case 'error': | ||
| this.flushPendingText(); | ||
| this.addEntry(logPhase, 'error', event.error.message); | ||
| this.addEntry(logPhase, 'error', extractErrorMessage(event.error)); | ||
| this.save(); | ||
| break; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this approach works, using type assertions like
(cause as { message?: unknown })can be brittle. A more robust and type-safe way to check for properties on anunknownorobjecttype is to use theinoperator. This avoids unsafe casting and makes the code's intent clearer.