Merge pull request #3840 from element-hq/valere/report_ec_error_to_sentry

Report group call errors to sentry
This commit is contained in:
Valere Fedronic
2026-04-08 11:21:12 +02:00
committed by GitHub
2 changed files with 59 additions and 0 deletions

View File

@@ -16,6 +16,7 @@ import {
} from "react"; } from "react";
import { BrowserRouter } from "react-router-dom"; import { BrowserRouter } from "react-router-dom";
import userEvent from "@testing-library/user-event"; import userEvent from "@testing-library/user-event";
import * as Sentry from "@sentry/react";
import { import {
type CallErrorRecoveryAction, type CallErrorRecoveryAction,
@@ -25,13 +26,26 @@ import {
ConnectionLostError, ConnectionLostError,
E2EENotSupportedError, E2EENotSupportedError,
type ElementCallError, type ElementCallError,
FailToGetOpenIdToken,
FailToStartLivekitConnection,
InsufficientCapacityError, InsufficientCapacityError,
MatrixRTCTransportMissingError, MatrixRTCTransportMissingError,
NoMatrix2AuthorizationService,
SFURoomCreationRestrictedError,
UnknownCallError, UnknownCallError,
} from "../utils/errors.ts"; } from "../utils/errors.ts";
import { mockConfig } from "../utils/test.ts"; import { mockConfig } from "../utils/test.ts";
import { ElementWidgetActions, type WidgetHelpers } from "../widget.ts"; import { ElementWidgetActions, type WidgetHelpers } from "../widget.ts";
// Mock Sentry before importing the component
vi.mock("@sentry/react", async () => {
const actual = await vi.importActual("@sentry/react");
return {
...actual,
captureException: vi.fn(),
};
});
test.each([ test.each([
{ {
error: new MatrixRTCTransportMissingError("example.com"), error: new MatrixRTCTransportMissingError("example.com"),
@@ -212,6 +226,44 @@ describe("Rageshake button", () => {
}); });
}); });
test.each([
{ error: new MatrixRTCTransportMissingError("example.com") },
{ error: new ConnectionLostError() },
{ error: new UnknownCallError(new Error("FOO")) },
{ error: new E2EENotSupportedError() },
{ error: new InsufficientCapacityError() },
{ error: new SFURoomCreationRestrictedError() },
{ error: new FailToStartLivekitConnection() },
{ error: new NoMatrix2AuthorizationService(new Error("FOO")) },
{ error: new FailToGetOpenIdToken(new Error("FOO")) },
])(
"should call Sentry.captureException for group call errors $error",
({ error }) => {
vi.mocked(Sentry.captureException).mockClear(); // Clear previous calls
const TestComponent = (): ReactNode => {
throw error;
};
render(
<BrowserRouter>
<GroupCallErrorBoundary
onError={vi.fn()}
recoveryActionHandler={vi.fn()}
widget={null}
>
<TestComponent />
</GroupCallErrorBoundary>
</BrowserRouter>,
);
// await screen.findByText(/Something went wrong/);
expect(Sentry.captureException).toHaveBeenCalledWith(error);
expect(Sentry.captureException).toHaveBeenCalledOnce();
},
);
test("should have a close button in widget mode", async () => { test("should have a close button in widget mode", async () => {
const error = new MatrixRTCTransportMissingError("example.com"); const error = new MatrixRTCTransportMissingError("example.com");
const TestComponent = (): ReactNode => { const TestComponent = (): ReactNode => {

View File

@@ -13,7 +13,9 @@ import {
type ReactNode, type ReactNode,
type SVGAttributes, type SVGAttributes,
useCallback, useCallback,
useEffect,
} from "react"; } from "react";
import * as Sentry from "@sentry/react";
import { Trans, useTranslation } from "react-i18next"; import { Trans, useTranslation } from "react-i18next";
import { import {
ErrorSolidIcon, ErrorSolidIcon,
@@ -53,6 +55,11 @@ const ErrorPage: FC<ErrorPageProps> = ({
recoveryActionHandler, recoveryActionHandler,
widget, widget,
}: ErrorPageProps): ReactElement => { }: ErrorPageProps): ReactElement => {
// We want to auto capture to sentry
useEffect(() => {
Sentry.captureException(error);
}, [error]);
const { t } = useTranslation(); const { t } = useTranslation();
logger.error("Error boundary caught:", error); logger.error("Error boundary caught:", error);
let icon: ComponentType<SVGAttributes<SVGElement>>; let icon: ComponentType<SVGAttributes<SVGElement>>;