refactor(copilot): use toError in remaining otel/finalize sites

Replace the last two `error instanceof Error ? error : new Error(String(error))`
patterns with toError from @sim/utils/errors. Completes the sweep of clean
candidates — no behavior change.
This commit is contained in:
Waleed Latif
2026-04-22 21:59:04 -07:00
parent d64e212eb7
commit 92405615dc
2 changed files with 4 additions and 3 deletions

View File

@@ -64,7 +64,7 @@ export async function finalizeStream(
span.setStatus({ code: SpanStatusCode.OK })
}
} catch (error) {
span.recordException(error instanceof Error ? error : new Error(String(error)))
span.recordException(toError(error))
span.setStatus({ code: SpanStatusCode.ERROR, message: 'finalize threw' })
throw error
} finally {

View File

@@ -10,6 +10,7 @@ import {
TraceFlags,
trace,
} from '@opentelemetry/api'
import { toError } from '@sim/utils/errors'
import { RequestTraceV1Outcome } from '@/lib/copilot/generated/request-trace-v1'
import {
CopilotBranchKind,
@@ -92,12 +93,12 @@ export function isActionableErrorStatus(code: number): boolean {
// client disconnect, internal timeout, uncategorized AbortError —
// becomes a real error that the dashboards will surface.
export function markSpanForError(span: Span, error: unknown): void {
const asError = error instanceof Error ? error : new Error(String(error))
const asError = toError(error)
span.recordException(asError)
if (!isExplicitUserStopError(error)) {
span.setStatus({
code: SpanStatusCode.ERROR,
message: error instanceof Error ? error.message : String(error),
message: asError.message,
})
}
}