From 82cc800415f3e6caff699d4a92e7a3eb4f7178e6 Mon Sep 17 00:00:00 2001 From: Christophe Vila Date: Sat, 19 Sep 2026 16:14:10 +0200 Subject: [PATCH] fix: don't attempt unlock with an empty password on first file pick UnlockViewModel.openFile(url:) called unlockWithPassword() immediately after saving the bookmark, but the first-open UI (openFileSection) has no password field yet -- password is still "" at that point, so every first file pick failed before the user could type anything. Picking a file now only saves the bookmark; the view naturally switches to the password-entry state for the user to unlock explicitly. Also makes KDBXError conform to LocalizedError with readable messages per case, so any error path that reaches the generic catch clause shows something useful instead of the default "The operation couldn't be completed (MyPassCore.KDBXError error N)". Found while testing the Phase 4 UI against a real KDBX file in the simulator. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01WYqycDFsynHH9VnnK7LNSf --- MyPass/ViewModels/UnlockViewModel.swift | 3 ++- .../Sources/MyPassCore/KDBX/KDBXError.swift | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/MyPass/ViewModels/UnlockViewModel.swift b/MyPass/ViewModels/UnlockViewModel.swift index 218e94c..0bce4a2 100644 --- a/MyPass/ViewModels/UnlockViewModel.swift +++ b/MyPass/ViewModels/UnlockViewModel.swift @@ -78,7 +78,8 @@ final class UnlockViewModel: ObservableObject { func openFile(url: URL) { do { try bookmarkService.save(url: url) - unlockWithPassword() + // Don't attempt to unlock yet -- picking a file only saves the bookmark. + // The view now shows the password field for the user to enter their password. } catch { errorMessage = error.localizedDescription } diff --git a/MyPassCore/Sources/MyPassCore/KDBX/KDBXError.swift b/MyPassCore/Sources/MyPassCore/KDBX/KDBXError.swift index b33214a..5d4c079 100644 --- a/MyPassCore/Sources/MyPassCore/KDBX/KDBXError.swift +++ b/MyPassCore/Sources/MyPassCore/KDBX/KDBXError.swift @@ -6,3 +6,18 @@ public enum KDBXError: Error, Equatable { case parseError(String) case writeError(String) } + +extension KDBXError: LocalizedError { + public var errorDescription: String? { + switch self { + case .invalidPassword: + return "Incorrect password." + case .fileNotFound: + return "The vault file could not be found." + case .parseError(let message): + return "Couldn't open the vault: \(message)" + case .writeError(let message): + return "Couldn't save the vault: \(message)" + } + } +}