[fractal/fractal-next] error: Report Secret Service errors



commit 104ed941785d93ce47167523400db227e7d6050c
Author: Enterprisey <59171-enterprisey users noreply gitlab gnome org>
Date:   Sun Oct 31 01:38:19 2021 -0700

    error: Report Secret Service errors
    
    Don't crash when unable to save session; show in-app notifications when
    either session saving or session restoring fails.
    
    Fix #796. Partial fix #808, because this change won't tell the user how
    to fix the error.

 src/matrix_error.rs | 10 ++++++++++
 src/session/mod.rs  | 30 ++++++++++++++++++++++++------
 src/window.rs       | 19 +++++++++++++++++--
 3 files changed, 51 insertions(+), 8 deletions(-)
---
diff --git a/src/matrix_error.rs b/src/matrix_error.rs
index d1f366aa..ab6324ab 100644
--- a/src/matrix_error.rs
+++ b/src/matrix_error.rs
@@ -52,3 +52,13 @@ impl UserFacingError for Error {
         }
     }
 }
+
+impl UserFacingError for secret_service::Error {
+    fn to_user_facing(self) -> String {
+        use secret_service::Error::*;
+        match self {
+            Locked => gettext("Keychain locked."),
+            _ => gettext("Secret Service error."),
+        }
+    }
+}
diff --git a/src/session/mod.rs b/src/session/mod.rs
index 00c0ae08..250b5837 100644
--- a/src/session/mod.rs
+++ b/src/session/mod.rs
@@ -36,7 +36,7 @@ use gtk::{
     gdk, glib, glib::clone, glib::source::SourceId, glib::SyncSender, CompositeTemplate,
     SelectionModel,
 };
-use log::{debug, error};
+use log::{debug, error, warn};
 use matrix_sdk::ruma::{
     api::client::r0::{
         filter::{FilterDefinition, LazyLoadOptions, RoomEventFilter, RoomFilter},
@@ -424,10 +424,28 @@ impl Session {
                     }
                 });
 
-                if store_session {
-                    // TODO: report secret service errors
-                    secret::store_session(&session).unwrap();
-                }
+                let res = if store_session {
+                    match secret::store_session(&session) {
+                        Ok(()) => None,
+                        Err(error) => {
+                            warn!("Couldn't store session: {:?}", error);
+                            let error_string = error.to_user_facing();
+                            Some(Error::new(move |_| {
+                                let error_label = gtk::LabelBuilder::new()
+                                    .label(
+                                        &(gettext("Unable to store session")
+                                            + ": "
+                                            + &error_string),
+                                    )
+                                    .wrap(true)
+                                    .build();
+                                Some(error_label.upcast())
+                            }))
+                        }
+                    }
+                } else {
+                    None
+                };
 
                 priv_.info.set(session).unwrap();
 
@@ -435,7 +453,7 @@ impl Session {
 
                 self.sync();
 
-                None
+                res
             }
             Err(error) => {
                 error!("Failed to prepare the session: {}", error);
diff --git a/src/window.rs b/src/window.rs
index 6a07ad27..2e3ded05 100644
--- a/src/window.rs
+++ b/src/window.rs
@@ -2,10 +2,11 @@ use crate::components::InAppNotification;
 use crate::config::{APP_ID, PROFILE};
 use crate::secret;
 use crate::Application;
-use crate::Error;
 use crate::Login;
 use crate::Session;
+use crate::{matrix_error::UserFacingError, Error};
 use adw::subclass::prelude::AdwApplicationWindowImpl;
+use gettextrs::gettext;
 use glib::signal::Inhibit;
 use gtk::subclass::prelude::*;
 use gtk::{self, prelude::*};
@@ -137,7 +138,21 @@ impl Window {
                     self.switch_to_sessions_page();
                 }
             }
-            Err(error) => warn!("Failed to restore previous sessions: {:?}", error),
+            Err(error) => {
+                warn!("Failed to restore previous sessions: {:?}", error);
+                let error_string = error.to_user_facing();
+                self.append_error(&Error::new(move |_| {
+                    let error_label = gtk::LabelBuilder::new()
+                        .label(
+                            &(gettext("Unable to restore previous sessions")
+                                + ": "
+                                + &error_string),
+                        )
+                        .wrap(true)
+                        .build();
+                    Some(error_label.upcast())
+                }));
+            }
         }
     }
 


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