Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add VaultErrorReport logic to browser extension login (#2159)
Leendert de Borstc737db93acf8
diff --git a/apps/browser-extension/src/entrypoints/popup/components/VaultErrorReport.tsx b/apps/browser-extension/src/entrypoints/popup/components/VaultErrorReport.tsxnew file mode 100644index 000000000..cb7b6551c--- /dev/null+++ b/apps/browser-extension/src/entrypoints/popup/components/VaultErrorReport.tsx@@ -0,0 +1,104 @@+import React, { useState } from 'react';+import { useTranslation } from 'react-i18next';++import { AppInfo } from '@/utils/AppInfo';+import { VaultProcessingError } from '@/utils/types/errors/VaultProcessingError';++/**+ * Vault error report props.+ */+type VaultErrorReportProps = {+ /** The vault-processing error to surface (its message + stack drive the copyable report). */+ error: VaultProcessingError;+};++/**+ * Renders a vault-processing error with an expandable technical-details section and a copy-to-clipboard button.+ *+ * Mirrors the mobile app's vault-error screen: the underlying failure (decrypt/materialize/format mismatch) is a+ * client-side problem that a generic "server unreachable" message hides, so we show the real error and let the+ * user copy a support-ready report (source, versions, message, stack trace).+ */+const VaultErrorReport: React.FC<VaultErrorReportProps> = ({ error }) => {+ const { t } = useTranslation();+ const [showDetails, setShowDetails] = useState(false);+ const [copied, setCopied] = useState(false);++ /**+ * Build the plain-text, support-ready error report copied to the clipboard.+ */+ const buildErrorReport = (): string => {+ return [+ `Source: ${error.source}`,+ `Extension: ${AppInfo.VERSION}`,+ `Browser: ${navigator.userAgent}`,+ `Error: ${error.message || t('common.errors.unknownError')}`,+ '',+ 'Stack trace:',+ error.stack ?? 'No stack trace available',+ ].join('\n');+ };++ /**+ * Copy the error report to the clipboard and briefly flip the button to a "copied" state.+ */+ const copyErrorReport = async (): Promise<void> => {+ try {+ await navigator.clipboard.writeText(buildErrorReport());+ setCopied(true);+ setTimeout(() => setCopied(false), 2000);+ } catch (err) {+ console.error('Failed to copy error report:', err);+ }+ };++ return (+ <div className="mb-4 rounded-lg border border-red-300 dark:border-red-800 bg-red-50 dark:bg-red-900/30 p-3">+ <p className="text-sm text-red-700 dark:text-red-300">+ {t('common.errors.vaultLoadError')}+ </p>+ <p className="mt-2 text-sm font-medium text-red-600 dark:text-red-400 break-words">+ {error.message || t('common.errors.unknownError')}+ </p>++ <button+ type="button"+ onClick={() => setShowDetails(!showDetails)}+ className="mt-2 text-xs font-medium text-red-600 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300 focus:outline-none"+ >+ {showDetails ? t('common.hideDetails') : t('common.showDetails')}+ </button>++ {showDetails && (+ <>+ <pre className="mt-2 max-h-40 overflow-auto whitespace-pre-wrap break-words rounded bg-red-100 dark:bg-gray-900 p-2 text-[11px] leading-snug text-red-900 dark:text-red-200 select-text">+ {buildErrorReport()}+ </pre>+ <button+ type="button"+ onClick={copyErrorReport}+ className={`mt-2 inline-flex items-center gap-1.5 rounded-md px-3 py-1.5 text-xs font-semibold text-white focus:outline-none focus:ring-2 focus:ring-offset-1 ${+ copied+ ? 'bg-green-600 hover:bg-green-600 focus:ring-green-500'+ : 'bg-red-600 hover:bg-red-700 focus:ring-red-500'+ }`}+ >+ <svg className="w-3.5 h-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">+ {copied ? (+ <polyline points="20 6 9 17 4 12" />+ ) : (+ <>+ <rect x="9" y="9" width="13" height="13" rx="2" ry="2" />+ <path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" />+ </>+ )}+ </svg>+ {copied ? t('common.copied') : t('common.copyToClipboard')}+ </button>+ </>+ )}+ </div>+ );+};++export default VaultErrorReport;diff --git a/apps/browser-extension/src/entrypoints/popup/pages/auth/Login.tsx b/apps/browser-extension/src/entrypoints/popup/pages/auth/Login.tsxindex 433a8d978..2f47fe4ae 100644--- a/apps/browser-extension/src/entrypoints/popup/pages/auth/Login.tsx+++ b/apps/browser-extension/src/entrypoints/popup/pages/auth/Login.tsx@@ -7,6 +7,7 @@ import MobileUnlockModal from '@/entrypoints/popup/components/Dialogs/MobileUnloimport HeaderButton from '@/entrypoints/popup/components/HeaderButton';import { HeaderIcon, HeaderIconType } from '@/entrypoints/popup/components/Icons/HeaderIcons';import LoginServerInfo from '@/entrypoints/popup/components/LoginServerInfo';+import VaultErrorReport from '@/entrypoints/popup/components/VaultErrorReport';import { useApp } from '@/entrypoints/popup/context/AppContext';import { useDb } from '@/entrypoints/popup/context/DbContext';import { useHeaderButtons } from '@/entrypoints/popup/context/HeaderButtonsContext';@@ -22,6 +23,7 @@ import { EncryptionUtility } from '@/utils/EncryptionUtility';import { sendMessage } from '@/utils/messaging/ExtensionMessaging';import { ApiAuthError } from '@/utils/types/errors/ApiAuthError';import { hasErrorCode, getErrorMessage } from '@/utils/types/errors/AppErrorCodes';+import { VaultProcessingError } from '@/utils/types/errors/VaultProcessingError';import type { MobileLoginResult } from '@/utils/types/messaging/MobileLoginResult';import { vaultStateEvents } from '@/events/VaultStateEvents';@@ -57,6 +59,7 @@ const Login: React.FC = () => {const [twoFactorCode, setTwoFactorCode] = useState('');const [clientUrl, setClientUrl] = useState<string | null>(null);const [error, setError] = useState<string | null>(null);+ const [vaultError, setVaultError] = useState<VaultProcessingError | null>(null);const [showMobileLoginModal, setShowMobileLoginModal] = useState(false);const webApi = useWebApi();const srpUtil = new SrpUtility(webApi);@@ -276,6 +279,7 @@ const Login: React.FC = () => {const handleSubmit = async (e: React.FormEvent) : Promise<void> => {e.preventDefault();setError(null);+ setVaultError(null);try {showLoading();@@ -344,8 +348,15 @@ const Login: React.FC = () => {loginResponse);} catch (err) {- // Show API authentication errors as-is.- if (err instanceof ApiAuthError) {+ console.error('Login error:', err);+ if (err instanceof ServerUpdateRequiredError) {+ // This client is v2-only; an outdated (self-hosted) server must be updated before login can proceed.+ setError(t('common.errors.serverVersionNotSupported'));+ } else if (err instanceof VaultProcessingError) {+ // The vault was fetched but couldn't be decrypted/materialized — surface the real error (copyable) for support.+ setVaultError(err);+ } else if (err instanceof ApiAuthError) {+ // Show API authentication errors as-is.setError(t('common.apiErrors.' + err.message));} else if (hasErrorCode(err)) {// Error contains an error code (E-XXX), show the formatted message as-is@@ -363,6 +374,7 @@ const Login: React.FC = () => {const handleTwoFactorSubmit = async (e: React.FormEvent) : Promise<void> => {e.preventDefault();setError(null);+ setVaultError(null);try {showLoading();@@ -491,6 +503,7 @@ const Login: React.FC = () => {{error}</div>)}+ {vaultError && <VaultErrorReport error={vaultError} />}<div className="mb-6"><p className="text-gray-700 dark:text-gray-200 mb-4">{t('auth.twoFactorTitle')}@@ -558,6 +571,7 @@ const Login: React.FC = () => {{error}</div>)}+ {vaultError && <VaultErrorReport error={vaultError} />}<div className="mb-4"><label className="block text-gray-700 dark:text-gray-200 font-medium mb-2" htmlFor="username">diff --git a/apps/browser-extension/src/i18n/locales/en.json b/apps/browser-extension/src/i18n/locales/en.jsonindex c7df2de4e..de46033ba 100644--- a/apps/browser-extension/src/i18n/locales/en.json+++ b/apps/browser-extension/src/i18n/locales/en.json@@ -114,6 +114,7 @@"vaultSyncTimeout": "Vault sync timed out. This can happen when the vault is large or the internet connection is slow. Please try again.","invalidCode": "Please enter a valid 6-digit authentication code.","serverError": "Could not reach AliasVault server. Please try again later or contact support if the problem persists.",+ "vaultLoadError": "Something went wrong while loading your vault. Please copy the error details below and contact support for help.","wrongPassword": "Incorrect password. Please try again.","sessionExpired": "Your session has expired. Please log in again.","mobileLoginRequestExpired": "Mobile login request timed out. Please reload the page and try again."diff --git a/apps/browser-extension/src/utils/types/errors/VaultProcessingError.ts b/apps/browser-extension/src/utils/types/errors/VaultProcessingError.tsnew file mode 100644index 000000000..57b5c38f8--- /dev/null+++ b/apps/browser-extension/src/utils/types/errors/VaultProcessingError.ts@@ -0,0 +1,32 @@+/**+ * Thrown when the vault cannot be loaded for a reason OTHER than the server being unreachable or outdated:+ * the encrypted snapshot was fetched successfully, but decrypting, unpacking, materializing, or reassembling+ * it into a local SQLite database failed. These are client-side (codec/format/integrity/corruption) failures.+ */+export class VaultProcessingError extends Error {+ /** Where in the flow the failure happened (for the copyable report, e.g. "vault-pull"). */+ public readonly source: string;++ /** The original error that caused this failure (kept for logging / inspection). */+ public readonly originalError: unknown;++ /**+ * Creates a new instance of VaultProcessingError.+ * @param source - a short identifier of the flow that failed (included in the copyable report).+ * @param originalError - the underlying error whose message + stack are preserved.+ */+ public constructor(source: string, originalError: unknown) {+ const causeMessage = originalError instanceof Error ? originalError.message : String(originalError);+ super(causeMessage);+ this.name = 'VaultProcessingError';+ this.source = source;+ this.originalError = originalError;++ // Preserve the original stack so the copyable report points at the real failure site, not this wrapper.+ if (originalError instanceof Error && originalError.stack) {+ this.stack = originalError.stack;+ }++ Object.setPrototypeOf(this, VaultProcessingError.prototype);+ }+}