Compare commits

...

1 Commits

Author SHA1 Message Date
Richard van der Hoff
cd173fcc61 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.
2025-02-13 18:45:16 +00:00
2 changed files with 29 additions and 2 deletions

View File

@@ -19,7 +19,6 @@ import {
} from "@vector-im/compound-web";
import CopyIcon from "@vector-im/compound-design-tokens/assets/web/icons/copy";
import KeyIcon from "@vector-im/compound-design-tokens/assets/web/icons/key-solid";
import { logger } from "matrix-js-sdk/src/logger";
import { _t } from "../../../../languageHandler";
import { EncryptionCard } from "./EncryptionCard";
@@ -27,6 +26,7 @@ import { useMatrixClientContext } from "../../../../contexts/MatrixClientContext
import { useAsyncMemo } from "../../../../hooks/useAsyncMemo";
import { copyPlaintext } from "../../../../utils/strings";
import { withSecretStorageKeyCache } from "../../../../SecurityManager";
import { logErrorAndShowErrorDialog } from "../../../../utils/ErrorUtils.tsx";
/**
* The possible states of the component.
@@ -130,7 +130,7 @@ export function ChangeRecoveryKey({
);
onFinish();
} catch (e) {
logger.error("Failed to bootstrap secret storage", e);
logErrorAndShowErrorDialog("Failed to set up secret storage", e);
}
}}
submitButtonLabel={

View File

@@ -8,11 +8,14 @@ Please see LICENSE files in the repository root for full details.
import React, { type ReactNode } from "react";
import { MatrixError, ConnectionError } from "matrix-js-sdk/src/matrix";
import { logger } from "matrix-js-sdk/src/logger";
import { _t, _td, lookupString, type Tags, type TranslatedString, type TranslationKey } from "../languageHandler";
import SdkConfig from "../SdkConfig";
import { type ValidatedServerConfig } from "./ValidatedServerConfig";
import ExternalLink from "../components/views/elements/ExternalLink";
import Modal from "../Modal.tsx";
import ErrorDialog from "../components/views/dialogs/ErrorDialog.tsx";
export const resourceLimitStrings = {
"monthly_active_user": _td("error|mau"),
@@ -191,3 +194,27 @@ export function messageForConnectionError(
return errorText;
}
/**
* Utility for handling unexpected errors: pops up the error dialog.
*
* Example usage:
* ```
* try {
* /// complicated operation
* } catch (e) {
* logErrorAndShowErrorDialog("Failed complicated operation", e);
* }
* ```
*
* This isn't particularly intended to be pretty; rather it lets the user know that *something* has gone wrong so that
* they can report a bug. The general idea is that it's better to let the user know of a failure, even if they
* can't do anything about it, than it is to fail silently with the appearance of success.
*
* @param title - Title for the error dialog.
* @param error - The thrown error. Becomes the content of the error dialog.
*/
export function logErrorAndShowErrorDialog(title: string, error: any): void {
logger.error(title, error);
Modal.createDialog(ErrorDialog, { title, description: `${error}` });
}