Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add extra error logging to vault_sync engine (#2159)

Leendert de Borstb2dd8c446bbd
diff --git a/apps/browser-extension/src/utils/SyncError.ts b/apps/browser-extension/src/utils/SyncError.ts
index 148fc1331..545bde22f 100644
--- a/apps/browser-extension/src/utils/SyncError.ts
+++ b/apps/browser-extension/src/utils/SyncError.ts
@@ -38,7 +38,8 @@ export function syncErrorMessage(detail: SyncErrorDetail, t: TFunction): string
}
if (detail.errorCode) {
const code = isErrorCode(detail.errorCode) ? detail.errorCode : AppErrorCode.UNKNOWN_ERROR;
- return formatErrorWithCode(t(getErrorTranslationKey(code)), code);
+ const message = formatErrorWithCode(t(getErrorTranslationKey(code)), code);
+ return detail.error ? `${message}\n${detail.error}` : message;
}
return detail.error;
}
diff --git a/core/client/src/api/errors/AppErrorCodes.ts b/core/client/src/api/errors/AppErrorCodes.ts
index b9ca7ecf7..002bda013 100644
--- a/core/client/src/api/errors/AppErrorCodes.ts
+++ b/core/client/src/api/errors/AppErrorCodes.ts
@@ -52,6 +52,9 @@ export enum AppErrorCode {
SYNC_STORE_FAILED = 'E-504', // Failed to store synced vault locally
SYNC_SERVER_UNREACHABLE = 'E-505', // Server unreachable and no local vault to fall back on
SYNC_SERVER_ERROR = 'E-506', // The server answered a sync request with an unexpected HTTP failure
+ SYNC_RESPONSE_INVALID = 'E-507', // A server response is not the JSON shape this client expects
+ SYNC_CODEC_FAILED = 'E-508', // The core library (codec, merge or crypto) refused the vault data
+ SYNC_ENGINE_FAILED = 'E-509', // The sync engine hit a state it has no rule for (the detail says which)
// Storage read/write errors (E-6xx)
STORAGE_READ_FAILED = 'E-601',
@@ -150,6 +153,9 @@ export function getErrorTranslationKey(code: AppErrorCode): string {
[AppErrorCode.SYNC_STORE_FAILED]: 'common.errors.unknownErrorTryAgain',
[AppErrorCode.SYNC_SERVER_UNREACHABLE]: 'common.errors.serverNotAvailable',
[AppErrorCode.SYNC_SERVER_ERROR]: 'common.errors.unknownErrorTryAgain',
+ [AppErrorCode.SYNC_RESPONSE_INVALID]: 'common.errors.unknownErrorTryAgain',
+ [AppErrorCode.SYNC_CODEC_FAILED]: 'common.errors.unknownErrorTryAgain',
+ [AppErrorCode.SYNC_ENGINE_FAILED]: 'common.errors.unknownErrorTryAgain',
// Storage read/write errors (E-6xx)
[AppErrorCode.STORAGE_READ_FAILED]: 'common.errors.unknownErrorTryAgain',
diff --git a/core/rust/src/vault_sync/errors.rs b/core/rust/src/vault_sync/errors.rs
index 66883f3a6..d1ad9c40b 100644
--- a/core/rust/src/vault_sync/errors.rs
+++ b/core/rust/src/vault_sync/errors.rs
@@ -28,6 +28,15 @@ pub enum ErrorCode {
/// The server answered a request with an unexpected HTTP failure.
#[serde(rename = "E-506")]
SyncServerError,
+ /// A server response (or a request body) is not the JSON shape this client expects.
+ #[serde(rename = "E-507")]
+ SyncResponseInvalid,
+ /// The core library (codec, merge or crypto) refused the vault data.
+ #[serde(rename = "E-508")]
+ SyncCodecFailed,
+ /// The engine hit a state it has no rule for; the message says which.
+ #[serde(rename = "E-509")]
+ SyncEngineFailed,
/// The host failed a read command (state, database, at-rest blob).
#[serde(rename = "E-601")]
StorageReadFailed,
@@ -167,7 +176,9 @@ impl SyncError {
SyncError::UploadRejected(_) | SyncError::MissingBlobs(_) => Failure::Coded(ErrorCode::UploadFailed),
SyncError::LegacyUpgradePending => Failure::Coded(ErrorCode::MigrationCheckFailed),
SyncError::Host { command, .. } => Failure::Coded(command.storage_error_code()),
- SyncError::Json(_) | SyncError::Core(_) | SyncError::Other(_) => Failure::Coded(ErrorCode::UnknownError),
+ SyncError::Json(_) => Failure::Coded(ErrorCode::SyncResponseInvalid),
+ SyncError::Core(_) => Failure::Coded(ErrorCode::SyncCodecFailed),
+ SyncError::Other(_) => Failure::Coded(ErrorCode::SyncEngineFailed),
}
}
@@ -200,4 +211,12 @@ mod tests {
assert_eq!(SyncError::Host { command: CommandKind::DbOpen, message: String::new() }.failure(), Failure::Coded(ErrorCode::DatabaseInitFailed));
assert_eq!(SyncError::Host { command: CommandKind::DbExec, message: String::new() }.failure(), Failure::Coded(ErrorCode::StorageWriteFailed));
}
+
+ #[test]
+ fn engine_internal_failures_carry_their_own_codes() {
+ assert_eq!(SyncError::Other("no rule".to_string()).failure(), Failure::Coded(ErrorCode::SyncEngineFailed));
+ assert_eq!(SyncError::Core(VaultError::General("codec".to_string())).failure(), Failure::Coded(ErrorCode::SyncCodecFailed));
+ assert_eq!(serde_json::from_str::<serde_json::Value>("nope").map_err(SyncError::Json).unwrap_err().failure(), Failure::Coded(ErrorCode::SyncResponseInvalid));
+ assert_eq!(serde_json::to_string(&ErrorCode::SyncEngineFailed).unwrap(), "\"E-509\"");
+ }
}