Skip to content

Commit 9240561

Browse files
committed
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.
1 parent d64e212 commit 9240561

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

apps/sim/lib/copilot/request/lifecycle/finalize.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export async function finalizeStream(
6464
span.setStatus({ code: SpanStatusCode.OK })
6565
}
6666
} catch (error) {
67-
span.recordException(error instanceof Error ? error : new Error(String(error)))
67+
span.recordException(toError(error))
6868
span.setStatus({ code: SpanStatusCode.ERROR, message: 'finalize threw' })
6969
throw error
7070
} finally {

apps/sim/lib/copilot/request/otel.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
TraceFlags,
1111
trace,
1212
} from '@opentelemetry/api'
13+
import { toError } from '@sim/utils/errors'
1314
import { RequestTraceV1Outcome } from '@/lib/copilot/generated/request-trace-v1'
1415
import {
1516
CopilotBranchKind,
@@ -92,12 +93,12 @@ export function isActionableErrorStatus(code: number): boolean {
9293
// client disconnect, internal timeout, uncategorized AbortError —
9394
// becomes a real error that the dashboards will surface.
9495
export function markSpanForError(span: Span, error: unknown): void {
95-
const asError = error instanceof Error ? error : new Error(String(error))
96+
const asError = toError(error)
9697
span.recordException(asError)
9798
if (!isExplicitUserStopError(error)) {
9899
span.setStatus({
99100
code: SpanStatusCode.ERROR,
100-
message: error instanceof Error ? error.message : String(error),
101+
message: asError.message,
101102
})
102103
}
103104
}

0 commit comments

Comments
 (0)