ChemPal Documentation - v1.15.1
    Preparing search index...

    Function trackRenderError

    • Reports a React render-boundary crash to PostHog as a $exception event, shaped like posthog-js's own captureException output ($exception_list with parsed stack frames, $exception_level), so it lands in PostHog's Error Tracking product with a stack-trace viewer, per-frame file/line, and automatic issue grouping. error_name/error_message are also kept as flat properties alongside the structured list, for any existing dashboard built on those two fields; error_cause is added the same way when error.cause is set, even though the full cause chain is also walked into $exception_list (see buildExceptionList) — this flat field makes the immediate cause filterable/visible without opening the stack trace.

      A caller-supplied { fatal: 1 } (as main.tsx's uncaught-root handler passes, for an error that escaped every boundary) is reported as an onuncaughtexception mechanism with handled: false; otherwise (an ErrorBoundary catch, which rendered a fallback UI) it's generic with handled: true.

      Parameters

      • error: unknown

        The caught error.

      • params: Record<string, AnalyticsValue> = {}

        Optional extra non-PII params.

      • OptionalcomponentStack: string

        The React component stack that was rendering when error was thrown (from ErrorBoundary.componentDidCatch or the root's onCaughtError/onUncaughtError), if available. Folded into the outermost $exception_list entry's stacktrace.component_stack — see buildExceptionList — rather than passed as a flat param, since it belongs with the stack trace it describes.

      Returns Promise<void>

      A promise that resolves once the send settles.

      void trackRenderError(new Error("Cannot read x of undefined"));
      void trackRenderError(error, { fatal: 1 }); // escaped every boundary
      void trackRenderError(error, {}, "in Boom\n in ErrorBoundary\n in App");
      export async function trackRenderError(
      error: unknown,
      params: Record<string, AnalyticsValue> = {},
      componentStack?: string,
      ): Promise<void> {
      const isError = error instanceof Error;
      const err = isError ? error : new Error(String(error));
      const fatal = params.fatal === 1;
      const mechanism: ExceptionMechanism = {
      type: fatal ? 'onuncaughtexception' : 'generic',
      handled: !fatal,
      synthetic: !isError,
      };
      return trackEvent('$exception', {
      app_version: __APP_VERSION__,
      error_name: err.name,
      error_message: err.message,
      ...(err.cause != null ? { error_cause: describeCause(err.cause) } : {}),
      $exception_list: buildExceptionList(err, mechanism, 0, componentStack),
      $exception_level: 'error',
      ...params,
      });
      }