Skip to content

Refactor ProviderError to include optional timing property and remove @ts-ignore usage #3180

@h30s

Description

@h30s

Problem Description

Across multiple AI provider implementations (OpenAI, Anthropic, vLLM, etc.), errors are currently handled by instantiating a standard Error object and dynamically attaching a timing property to it. Since the standard Error interface does not include timing, this is achieved using // @ts-ignore to bypass TypeScript validation.

Example from apps/sim/providers/openai/index.ts:

const enhancedError = new Error(error instanceof Error ? error.message : String(error))
// @ts-ignore - Adding timing property to the error
enhancedError.timing = {
  startTime: providerStartTimeISO,
  endTime: providerEndTimeISO,
  duration: totalDuration,
}
throw enhancedError

This pattern is repeated in approximately 13 provider files. It weakens type safety, relies on "any" casting (via ignore), and makes the error contract implicit rather than explicit.

Why this matters

  • Type Safety: Removing @ ts-ignore ensures that we are not inadvertently suppressing other potential type errors.
  • Maintainability: A proper ProviderError interface makes the code self-documenting and easier to refactor.
  • Consistency: Centralizing the error definition ensures all providers return errors with the same structure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions