Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add exception models (#2159)
Leendert de Borst9529218b6f81
diff --git a/apps/server/AliasVault.Client/Services/VaultSync/Exceptions/VaultKeyDecryptException.cs b/apps/server/AliasVault.Client/Services/VaultSync/Exceptions/VaultKeyDecryptException.csnew file mode 100644index 000000000..e653998fe--- /dev/null+++ b/apps/server/AliasVault.Client/Services/VaultSync/Exceptions/VaultKeyDecryptException.cs@@ -0,0 +1,23 @@+//-----------------------------------------------------------------------+// <copyright file="VaultKeyDecryptException.cs" company="aliasvault">+// Copyright (c) aliasvault. All rights reserved.+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.+// </copyright>+//-----------------------------------------------------------------------++namespace AliasVault.Client.Services.VaultSync.Exceptions;++/// <summary>+/// Thrown when a wrapped key of the unlock chain does not open with the given key, which for the password method means the password is wrong.+/// </summary>+public sealed class VaultKeyDecryptException : Exception+{+ /// <summary>+ /// Initializes a new instance of the <see cref="VaultKeyDecryptException"/> class.+ /// </summary>+ /// <param name="innerException">The underlying decryption error.</param>+ public VaultKeyDecryptException(Exception? innerException = null)+ : base("Failed to decrypt the vault encryption key.", innerException)+ {+ }+}diff --git a/apps/server/AliasVault.Client/Services/VaultSync/Exceptions/VaultKeyUnavailableException.cs b/apps/server/AliasVault.Client/Services/VaultSync/Exceptions/VaultKeyUnavailableException.csnew file mode 100644index 000000000..c7522baca--- /dev/null+++ b/apps/server/AliasVault.Client/Services/VaultSync/Exceptions/VaultKeyUnavailableException.cs@@ -0,0 +1,23 @@+//-----------------------------------------------------------------------+// <copyright file="VaultKeyUnavailableException.cs" company="aliasvault">+// Copyright (c) aliasvault. All rights reserved.+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.+// </copyright>+//-----------------------------------------------------------------------++namespace AliasVault.Client.Services.VaultSync.Exceptions;++/// <summary>+/// Thrown when the server cannot be reached and no cached key material exists to unlock with offline.+/// </summary>+public sealed class VaultKeyUnavailableException : Exception+{+ /// <summary>+ /// Initializes a new instance of the <see cref="VaultKeyUnavailableException"/> class.+ /// </summary>+ /// <param name="innerException">The network error that prevented fetching the vault key.</param>+ public VaultKeyUnavailableException(Exception? innerException = null)+ : base("The vault key could not be fetched from the server and no cached copy exists.", innerException)+ {+ }+}diff --git a/apps/server/AliasVault.Client/Services/VaultSync/Exceptions/VaultProcessingException.cs b/apps/server/AliasVault.Client/Services/VaultSync/Exceptions/VaultProcessingException.csnew file mode 100644index 000000000..59f251ab9--- /dev/null+++ b/apps/server/AliasVault.Client/Services/VaultSync/Exceptions/VaultProcessingException.cs@@ -0,0 +1,56 @@+//-----------------------------------------------------------------------+// <copyright file="VaultProcessingException.cs" company="aliasvault">+// Copyright (c) aliasvault. All rights reserved.+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.+// </copyright>+//-----------------------------------------------------------------------++namespace AliasVault.Client.Services.VaultSync.Exceptions;++using System.Text;++/// <summary>+/// Thrown when the vault was fetched but could not be decrypted, unpacked or materialized locally. Distinct from+/// network errors so the UI can surface the technical detail as a support report.+/// </summary>+public sealed class VaultProcessingException : Exception+{+ /// <summary>+ /// Initializes a new instance of the <see cref="VaultProcessingException"/> class.+ /// </summary>+ /// <param name="source">Short identifier of the flow that failed, e.g. "vault-pull".</param>+ /// <param name="innerException">The underlying error.</param>+ public VaultProcessingException(string source, Exception innerException)+ : base(innerException.Message, innerException)+ {+ FlowSource = source;+ }++ /// <summary>+ /// Gets the flow that failed.+ /// </summary>+ public string FlowSource { get; }++ /// <summary>+ /// Builds the plain-text support report for this failure.+ /// </summary>+ /// <returns>The report text.</returns>+ public string ToReport()+ {+ var report = new StringBuilder();+ report.AppendLine($"Source: {FlowSource}");+ report.AppendLine($"Error: {InnerException?.GetType().Name}: {Message}");+ for (var inner = InnerException?.InnerException; inner is not null; inner = inner.InnerException)+ {+ report.AppendLine($"Caused by: {inner.GetType().Name}: {inner.Message}");+ }++ if (!string.IsNullOrEmpty(InnerException?.StackTrace))+ {+ report.AppendLine();+ report.AppendLine(InnerException.StackTrace);+ }++ return report.ToString().TrimEnd();+ }+}