[fractal/not-so-secret: 2/3] passwd: improve password storage error handling




commit 5b4a6182497a6a03313d7eb36e2c4b4e352e3d64
Author: Alexandre Franke <afranke gnome org>
Date:   Mon Jan 4 09:59:57 2021 +0100

    passwd: improve password storage error handling

 fractal-gtk/src/appop/login.rs | 14 ++++++++------
 fractal-gtk/src/passwd.rs      |  4 ++--
 2 files changed, 10 insertions(+), 8 deletions(-)
---
diff --git a/fractal-gtk/src/appop/login.rs b/fractal-gtk/src/appop/login.rs
index 8f86a709..211e167f 100644
--- a/fractal-gtk/src/appop/login.rs
+++ b/fractal-gtk/src/appop/login.rs
@@ -85,16 +85,18 @@ impl AppOp {
         server: Url,
         identity: Box<ServerName>,
     ) {
-        self.store_pass(
+        match self.store_pass(
             username.clone(),
             password.clone(),
             server.clone(),
             identity.clone(),
-        )
-        .unwrap_or_else(|_| {
-            // TODO: show an error
-            error!("Can't store the password using libsecret");
-        });
+        ) {
+            Err(SsError::Locked) => error!("Can’t store the password, keyring is locked."),
+            Err(SsError::Dbus(_)) => {
+                error!("Can’t store the password, no Secret Service available.")
+            }
+            _ => (),
+        };
 
         RUNTIME.spawn(async move {
             match register::login(username, password, server.clone()).await {
diff --git a/fractal-gtk/src/passwd.rs b/fractal-gtk/src/passwd.rs
index 995aa3e0..714342cf 100644
--- a/fractal-gtk/src/passwd.rs
+++ b/fractal-gtk/src/passwd.rs
@@ -39,7 +39,7 @@ pub trait PasswordStorage {
         password: String,
         server: Url,
         identity: Box<ServerName>,
-    ) -> Result<(), Error> {
+    ) -> Result<(), secret_service::SsError> {
         ss_storage::store_pass(username, password, server, identity)
     }
 
@@ -140,7 +140,7 @@ mod ss_storage {
         password: String,
         server: Url,
         identity: Box<ServerName>,
-    ) -> Result<(), Error> {
+    ) -> Result<(), secret_service::SsError> {
         let ss = SecretService::new(EncryptionType::Dh)?;
         let collection = get_default_collection_unlocked(&ss)?;
         let key = "fractal";


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]