Use error.cause instead of name to detect sticky-events failure

This commit is contained in:
fkwp
2026-06-10 12:49:28 +02:00
parent 49168d01fa
commit 5d0047aebe
2 changed files with 31 additions and 13 deletions

View File

@@ -19,7 +19,12 @@ import {
vitest, vitest,
} from "vitest"; } from "vitest";
import { render, waitFor, screen, act } from "@testing-library/react"; import { render, waitFor, screen, act } from "@testing-library/react";
import { type MatrixClient, JoinRule, type RoomState } from "matrix-js-sdk"; import {
type MatrixClient,
JoinRule,
type RoomState,
UnsupportedStickyEventsEndpointError,
} from "matrix-js-sdk";
import { import {
MatrixRTCSessionEvent, MatrixRTCSessionEvent,
type MatrixRTCSession, type MatrixRTCSession,
@@ -410,19 +415,26 @@ test.skip("GroupCallView shows errors that occur during joining", async () => {
screen.getByText("Call is not supported"); screen.getByText("Call is not supported");
}); });
test("translates UnsupportedStickyEventsEndpointError to the StickyEventsRequiredError screen", async () => { test("translates wrapped UnsupportedStickyEventsEndpointError to the StickyEventsRequiredError screen", async () => {
// Match the shape the SDK emits on // Mirror the shape the SDK emits: the MembershipManager scheduler wraps
// MatrixRTCSessionEvent.MembershipManagerError when matrix_2_0 mode is // the original UnsupportedStickyEventsEndpointError in a generic Error
// configured but the homeserver does not advertise MSC4354. // but preserves the original on `.cause`.
const stickyError = new Error("Server does not support the sticky events"); const stickyError = new UnsupportedStickyEventsEndpointError(
stickyError.name = "UnsupportedStickyEventsEndpointError"; "Server does not support the sticky events",
"sendStickyEvent",
);
const wrappedError = new Error(
"The MembershipManager shut down because of the end condition: " +
String(stickyError),
{ cause: stickyError },
);
const { rtcSession } = createGroupCallView(null, true, { const { rtcSession } = createGroupCallView(null, true, {
withErrorBoundary: true, withErrorBoundary: true,
}); });
await act(() => await act(() =>
rtcSession.emit(MatrixRTCSessionEvent.MembershipManagerError, stickyError), rtcSession.emit(MatrixRTCSessionEvent.MembershipManagerError, wrappedError),
); );
await screen.findByText("Homeserver does not support Matrix 2.0 calls"); await screen.findByText("Homeserver does not support Matrix 2.0 calls");

View File

@@ -13,7 +13,12 @@ import {
useMemo, useMemo,
useState, useState,
} from "react"; } from "react";
import { type MatrixClient, JoinRule, type Room } from "matrix-js-sdk"; import {
type MatrixClient,
JoinRule,
type Room,
UnsupportedStickyEventsEndpointError,
} from "matrix-js-sdk";
import { import {
Room as LivekitRoom, Room as LivekitRoom,
isE2EESupported as isE2EESupportedBrowser, isE2EESupported as isE2EESupportedBrowser,
@@ -164,12 +169,13 @@ export const GroupCallView: FC<Props> = ({
rtcSession, rtcSession,
MatrixRTCSessionEvent.MembershipManagerError, MatrixRTCSessionEvent.MembershipManagerError,
(error) => { (error) => {
// The SDK throws this typed error when matrix_rtc_mode=matrix_2_0 is in // When matrix_rtc_mode=matrix_2_0 is in effect but the homeserver does
// effect but the homeserver does not advertise MSC4354 (sticky events). // not advertise MSC4354 (sticky events), the SDK throws an
// Surface the actual cause instead of a generic connection-lost screen. // `UnsupportedStickyEventsEndpointError`. The MembershipManager
// scheduler wraps it and exposes the original via `.cause`.
if ( if (
error instanceof Error && error instanceof Error &&
error.name === "UnsupportedStickyEventsEndpointError" error.cause instanceof UnsupportedStickyEventsEndpointError
) { ) {
setExternalError(new StickyEventsRequiredError()); setExternalError(new StickyEventsRequiredError());
} else { } else {