Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Remove exception swallowing
Browse files Browse the repository at this point in the history
This seems like it causes more problems than it solves.
  • Loading branch information
richvdh committed May 24, 2023
1 parent 2cff520 commit de9190b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 30 deletions.
13 changes: 4 additions & 9 deletions src/utils/device/isDeviceVerified.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,10 @@ import { MatrixClient } from "matrix-js-sdk/src/matrix";
* indicating whether the device has been cross-signed by a cross-signing key we trust.
*/
export const isDeviceVerified = async (client: MatrixClient, deviceId: string): Promise<boolean | null> => {
try {
const trustLevel = await client.getCrypto()?.getDeviceVerificationStatus(client.getSafeUserId(), deviceId);
if (!trustLevel) {
// either no crypto, or an unknown/no-e2e device
return null;
}
return trustLevel.crossSigningVerified;
} catch (e) {
console.error("Error getting device cross-signing info", e);
const trustLevel = await client.getCrypto()?.getDeviceVerificationStatus(client.getSafeUserId(), deviceId);
if (!trustLevel) {
// either no crypto, or an unknown/no-e2e device
return null;
}
return trustLevel.crossSigningVerified;
};
Original file line number Diff line number Diff line change
Expand Up @@ -227,27 +227,6 @@ describe("<SessionManagerTab />", () => {
expect(container.getElementsByClassName("mx_Spinner").length).toBeFalsy();
});

it("does not fail when checking device verification fails", async () => {
const logSpy = jest.spyOn(console, "error").mockImplementation((e) => {});
mockClient.getDevices.mockResolvedValue({
devices: [alicesDevice, alicesMobileDevice],
});
const failError = new Error("non-specific failure");
mockCrypto.getDeviceVerificationStatus.mockImplementation(() => {
throw failError;
});
render(getComponent());

await act(async () => {
await flushPromises();
});

// called for each device despite error
expect(mockCrypto.getDeviceVerificationStatus).toHaveBeenCalledWith(aliceId, alicesDevice.device_id);
expect(mockCrypto.getDeviceVerificationStatus).toHaveBeenCalledWith(aliceId, alicesMobileDevice.device_id);
expect(logSpy).toHaveBeenCalledWith("Error getting device cross-signing info", failError);
});

it("sets device verification status correctly", async () => {
mockClient.getDevices.mockResolvedValue({
devices: [alicesDevice, alicesMobileDevice, alicesOlderMobileDevice],
Expand Down

0 comments on commit de9190b

Please sign in to comment.