• Captures an error to Sentry for monitoring and analysis in production. Wraps error creation with Sentry integration, sending errors when configured.

    Parameters

    • type: ErrorType

      The error type.

    • message: string

      The error message.

    • originalError: unknown

      The original error object.

    • Optionalcontext: Record<string, unknown>

      Optional metadata to include with the error.

    • Optionalcode: string

      Optional error code for categorization.

    • OptionalrecoveryAction: ErrorRecoveryAction

      Optional recovery action hint for the UI.

    • OptionalrecoveryMessage: string

      Optional user-friendly recovery instruction.

    Returns AppError

    The constructed AppError object.

    export function captureError(
    type: ErrorType,
    message: string,
    originalError: unknown,
    context?: Record<string, unknown>,
    code?: string,
    recoveryAction?: ErrorRecoveryAction,
    recoveryMessage?: string,
    ): AppError {
    const appError = createError(
    type,
    message,
    originalError,
    code,
    recoveryAction,
    recoveryMessage,
    );

    // Only capture to Sentry in production or when SENTRY_DSN is configured
    if (
    globalThis.window !== undefined &&
    (import.meta.env.MODE === "production" || import.meta.env.VITE_SENTRY_DSN)
    ) {
    // Dynamic import to avoid hard dependency on Sentry
    import("@sentry/electron/renderer")
    .then((Sentry) => {
    Sentry.captureException(originalError, {
    tags: {
    errorType: type,
    errorCode: code || "UNKNOWN",
    recoveryAction: recoveryAction || "none",
    },
    contexts: context
    ? {
    app: context,
    }
    : undefined,
    });
    })
    .catch((err) => {
    console.debug(
    "[ErrorHandling] Failed to capture error to Sentry:",
    err,
    );
    });
    }

    return appError;
    }