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

    Function installErrorCapture

    • Registers global error and unhandledrejection listeners that push captured exceptions into the ring buffer. Idempotent, and safe in both window and service-worker contexts (both expose self with addEventListener).

      Returns void

      Nothing.

      installErrorCapture(); // call once per context, before the app runs
      
      export function installErrorCapture(): void {
      if (captureInstalled) return;
      if (typeof self === 'undefined' || typeof self.addEventListener !== 'function') return;
      captureInstalled = true;

      self.addEventListener('error', (event: ErrorEvent) => {
      const described = event.error ? describeError(event.error) : { message: event.message };
      // An exception nothing caught: this page's work stops, so it is fatal.
      logger.fatal(`Uncaught exception: ${described.message}`, {
      error: event.error,
      filename: event.filename,
      lineno: event.lineno,
      colno: event.colno,
      });
      void recordError({ source: 'window', ...described });
      });

      self.addEventListener('unhandledrejection', (event: PromiseRejectionEvent) => {
      // A stopped search rejects with its abort reason; that is expected, not a bug.
      if (!isExpectedAbort(event.reason)) {
      logger.error(`Unhandled promise rejection: ${getErrorMessage(event.reason)}`, {
      error: event.reason,
      });
      }
      void recordError({ source: 'unhandledrejection', ...describeError(event.reason) });
      });
      }