Skip to content

Commit cd173fc

Browse files
committed
CreateSecretStorageDialog: error handling
I'm fed up with setup operations in EW failing silently. Rather than leaving the user with a mysteriously broken client, let's at least tell them that something has gone wrong, so that they can report the issue and we can investigate. Obviously, showing an unactionable Error dialog is a last resort: ideally, we should handle the error ourselves, or give the user actionable steps to resolve the problem. But that takes significant design and engineering. Just swallowing errors is the worst of all possible options.
1 parent 2abd534 commit cd173fc

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/components/views/settings/encryption/ChangeRecoveryKey.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ import {
1919
} from "@vector-im/compound-web";
2020
import CopyIcon from "@vector-im/compound-design-tokens/assets/web/icons/copy";
2121
import KeyIcon from "@vector-im/compound-design-tokens/assets/web/icons/key-solid";
22-
import { logger } from "matrix-js-sdk/src/logger";
2322

2423
import { _t } from "../../../../languageHandler";
2524
import { EncryptionCard } from "./EncryptionCard";
2625
import { useMatrixClientContext } from "../../../../contexts/MatrixClientContext";
2726
import { useAsyncMemo } from "../../../../hooks/useAsyncMemo";
2827
import { copyPlaintext } from "../../../../utils/strings";
2928
import { withSecretStorageKeyCache } from "../../../../SecurityManager";
29+
import { logErrorAndShowErrorDialog } from "../../../../utils/ErrorUtils.tsx";
3030

3131
/**
3232
* The possible states of the component.
@@ -130,7 +130,7 @@ export function ChangeRecoveryKey({
130130
);
131131
onFinish();
132132
} catch (e) {
133-
logger.error("Failed to bootstrap secret storage", e);
133+
logErrorAndShowErrorDialog("Failed to set up secret storage", e);
134134
}
135135
}}
136136
submitButtonLabel={

src/utils/ErrorUtils.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ Please see LICENSE files in the repository root for full details.
88

99
import React, { type ReactNode } from "react";
1010
import { MatrixError, ConnectionError } from "matrix-js-sdk/src/matrix";
11+
import { logger } from "matrix-js-sdk/src/logger";
1112

1213
import { _t, _td, lookupString, type Tags, type TranslatedString, type TranslationKey } from "../languageHandler";
1314
import SdkConfig from "../SdkConfig";
1415
import { type ValidatedServerConfig } from "./ValidatedServerConfig";
1516
import ExternalLink from "../components/views/elements/ExternalLink";
17+
import Modal from "../Modal.tsx";
18+
import ErrorDialog from "../components/views/dialogs/ErrorDialog.tsx";
1619

1720
export const resourceLimitStrings = {
1821
"monthly_active_user": _td("error|mau"),
@@ -191,3 +194,27 @@ export function messageForConnectionError(
191194

192195
return errorText;
193196
}
197+
198+
/**
199+
* Utility for handling unexpected errors: pops up the error dialog.
200+
*
201+
* Example usage:
202+
* ```
203+
* try {
204+
* /// complicated operation
205+
* } catch (e) {
206+
* logErrorAndShowErrorDialog("Failed complicated operation", e);
207+
* }
208+
* ```
209+
*
210+
* This isn't particularly intended to be pretty; rather it lets the user know that *something* has gone wrong so that
211+
* they can report a bug. The general idea is that it's better to let the user know of a failure, even if they
212+
* can't do anything about it, than it is to fail silently with the appearance of success.
213+
*
214+
* @param title - Title for the error dialog.
215+
* @param error - The thrown error. Becomes the content of the error dialog.
216+
*/
217+
export function logErrorAndShowErrorDialog(title: string, error: any): void {
218+
logger.error(title, error);
219+
Modal.createDialog(ErrorDialog, { title, description: `${error}` });
220+
}

0 commit comments

Comments
 (0)