The caught error.
Optional extra non-PII params.
OptionalcomponentStack: stringThe 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.
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,
});
}
Reports a React render-boundary crash to PostHog as a
$exceptionevent, shaped likeposthog-js's owncaptureExceptionoutput ($exception_listwith 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_messageare also kept as flat properties alongside the structured list, for any existing dashboard built on those two fields;error_causeis added the same way whenerror.causeis set, even though the full cause chain is also walked into$exception_list(seebuildExceptionList) — this flat field makes the immediate cause filterable/visible without opening the stack trace.A caller-supplied
{ fatal: 1 }(asmain.tsx's uncaught-root handler passes, for an error that escaped every boundary) is reported as anonuncaughtexceptionmechanism withhandled: false; otherwise (anErrorBoundarycatch, which rendered a fallback UI) it'sgenericwithhandled: true.