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

    Function collectDiagnostics

    • Collects a full diagnostics snapshot. When called with a specific error, its message and stack lead the report; otherwise the report is "manual" and the ring buffer of recent exceptions stands in for the stack.

      Parameters

      • Optionalerror: unknown

        The error that triggered the report, if any.

      • context: ReportContext = {}

        Optional page URL, action label, and extra payload.

      Returns Promise<Diagnostics>

      The assembled diagnostics.

      const diag = await collectDiagnostics(err, { action: "render-crash" });
      diag.message; // err.message
      export async function collectDiagnostics(
      error?: unknown,
      context: ReportContext = {},
      ): Promise<Diagnostics> {
      const recentErrors = await getRecentErrors();
      const isError = error instanceof Error;
      const message = isError ? error.message : error ? String(error) : 'Manual bug report';
      const stack = isError ? formatErrorChain(error) : '';

      return {
      message,
      stack,
      version: readVersion(),
      userAgent: readUserAgent(),
      language: navigator.language,
      url: context.url ?? globalThis.location?.href ?? 'n/a',
      action: context.action ?? 'n/a',
      installSource: readInstallSource(),
      storage: await readStorageSummary(),
      recentErrors,
      extra: context.extra,
      timestamp: new Date().toISOString(),
      };
      }