mirror of
https://github.com/simstudioai/sim.git
synced 2026-04-28 03:00:29 -04:00
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:
@@ -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 {
|
||||
|
||||
@@ -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,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user