diff --git a/linux/changelog.d/4234.fixed.md b/linux/changelog.d/4234.fixed.md new file mode 100644 index 0000000000..36c8a9745a --- /dev/null +++ b/linux/changelog.d/4234.fixed.md @@ -0,0 +1 @@ +Locked-keyring errors omitted the steps to create a default keyring. diff --git a/linux/crates/app/src/services/secret_save_report.rs b/linux/crates/app/src/services/secret_save_report.rs index 29afb40a2c..b5309cdb79 100644 --- a/linux/crates/app/src/services/secret_save_report.rs +++ b/linux/crates/app/src/services/secret_save_report.rs @@ -175,13 +175,9 @@ impl SecretSaveReport { } } - // The Secret portal answers a missing default keyring the same way as a locked one - // (linux/docs/troubleshooting.md, Flatpak connections). fn remedy(&self) -> Option { match Reason::of(&self.error) { - Reason::Locked => Some(gettext( - "Unlock the keyring, accept its prompt and try again. With automatic login, GNOME may have no default keyring yet: create one in Passwords and Keys and make it the default.", - )), + Reason::Locked => Some(keyring_locked_recovery()), Reason::NoKeyring => Some(match self.error { SecretError::PortalUnavailable { .. } => { gettext("Install xdg-desktop-portal and your desktop’s keyring, then log out and in.") @@ -193,6 +189,15 @@ impl SecretSaveReport { } } +/// The way out of a locked keyring, shared by every surface that reads or saves a secret. The +/// Secret portal answers a missing default keyring the same way as a locked one, so the advice +/// covers both (linux/docs/troubleshooting.md, Flatpak connections). +pub(crate) fn keyring_locked_recovery() -> String { + gettext( + "Unlock the keyring, accept its prompt and try again. With automatic login, GNOME may have no default keyring yet: create one in Passwords and Keys and make it the default.", + ) +} + /// A session's credentials whose saves are reported. A secret typed at a reconnect prompt is /// stored by the session's health monitor, which only logs a refusal. pub(crate) struct ReportingCredentials { diff --git a/linux/crates/app/src/ui/assistant/error_text.rs b/linux/crates/app/src/ui/assistant/error_text.rs index 0864a2edf0..b8c1167e47 100644 --- a/linux/crates/app/src/ui/assistant/error_text.rs +++ b/linux/crates/app/src/ui/assistant/error_text.rs @@ -83,9 +83,11 @@ fn with_server_words(sentence: String, server: Option<&str>) -> String { /// assistant cannot do without it. fn keyring_text(error: &SecretError) -> String { match error { - SecretError::Locked | SecretError::UnlockDismissed => { - crate::i18n::gettext("The keyring is locked, so the API key cannot be read. Unlock it and try again.") - } + SecretError::Locked | SecretError::UnlockDismissed => format!( + "{} {}", + crate::i18n::gettext("The keyring is locked, so the API key cannot be read."), + crate::services::secret_save_report::keyring_locked_recovery(), + ), SecretError::ServiceUnavailable { .. } => crate::i18n::gettext( "No keyring is running, so the API key cannot be read or kept. Start a keyring and try again.", ), @@ -167,4 +169,20 @@ mod tests { assert_eq!(text, "Add your OpenAI API key in Preferences."); } + + #[test] + fn a_locked_key_explains_default_keyring_recovery() { + for error in [SecretError::Locked, SecretError::UnlockDismissed] { + let text = setup_error_text(&AiSetupError::Keyring(error)); + + assert!( + text.starts_with("The keyring is locked, so the API key cannot be read."), + "{text}" + ); + assert!( + text.contains("create one in Passwords and Keys and make it the default."), + "{text}" + ); + } + } } diff --git a/linux/crates/app/src/ui/error_text/saved_connection.rs b/linux/crates/app/src/ui/error_text/saved_connection.rs index a2390271b2..4f927fb507 100644 --- a/linux/crates/app/src/ui/error_text/saved_connection.rs +++ b/linux/crates/app/src/ui/error_text/saved_connection.rs @@ -55,7 +55,8 @@ mod tests { fn each_failure_says_what_happened() { assert_eq!( saved_connection_error_message(&SavedConnectionError::Secret(SecretError::Locked)), - "The keyring is locked. Unlock it and try again." + "The keyring is locked. Unlock the keyring, accept its prompt and try again. With automatic login, \ + GNOME may have no default keyring yet: create one in Passwords and Keys and make it the default." ); assert_eq!( saved_connection_error_message(&SavedConnectionError::NotFound(Uuid::nil())), diff --git a/linux/crates/app/src/ui/error_text/secret.rs b/linux/crates/app/src/ui/error_text/secret.rs index be75b0b9f9..20480d17de 100644 --- a/linux/crates/app/src/ui/error_text/secret.rs +++ b/linux/crates/app/src/ui/error_text/secret.rs @@ -10,10 +10,16 @@ pub(super) fn secret_message(error: &tablepro_core::credentials::SecretError) -> SecretError::PortalUnavailable { .. } => crate::i18n::gettext( "The secret portal is unavailable, so saved passwords cannot be read inside the sandbox. Check that xdg-desktop-portal and a keyring are running, or enter the password by hand.", ), - SecretError::Locked => crate::i18n::gettext("The keyring is locked. Unlock it and try again."), - SecretError::UnlockDismissed => { - crate::i18n::gettext("The keyring stayed locked because the unlock prompt was dismissed.") - } + SecretError::Locked => format!( + "{} {}", + crate::i18n::gettext("The keyring is locked."), + crate::services::secret_save_report::keyring_locked_recovery(), + ), + SecretError::UnlockDismissed => format!( + "{} {}", + crate::i18n::gettext("The keyring stayed locked because the unlock prompt was dismissed."), + crate::services::secret_save_report::keyring_locked_recovery(), + ), SecretError::InvalidEncoding => { crate::i18n::gettext("The stored password is not readable text. Enter it again to replace it.") } diff --git a/linux/crates/app/src/ui/preferences_dialog/mcp_page.rs b/linux/crates/app/src/ui/preferences_dialog/mcp_page.rs index 3a24c6ff81..646604c265 100644 --- a/linux/crates/app/src/ui/preferences_dialog/mcp_page.rs +++ b/linux/crates/app/src/ui/preferences_dialog/mcp_page.rs @@ -1124,9 +1124,11 @@ pub(crate) fn failure_text(failure: &McpFailure) -> String { // server cannot do without it. fn keyring_text(error: &SecretError) -> String { match error { - SecretError::Locked | SecretError::UnlockDismissed => { - gettext("The keyring is locked, so the access token cannot be read. Unlock it and try again.") - } + SecretError::Locked | SecretError::UnlockDismissed => format!( + "{} {}", + gettext("The keyring is locked, so the access token cannot be read."), + crate::services::secret_save_report::keyring_locked_recovery(), + ), SecretError::ServiceUnavailable { .. } => { gettext("No keyring is running, so the access token cannot be kept. Start a keyring and try again.") } @@ -1687,6 +1689,39 @@ mod tests { assert_eq!(texts.len(), statuses.len()); } + #[test] + fn locked_token_status_explains_default_keyring_recovery() { + for error in [SecretError::Locked, SecretError::UnlockDismissed] { + let text = status_text(&McpStatus::Failed(McpFailure::Keyring(error))); + + assert!(text.contains("The keyring is locked, so the access token cannot be read.")); + assert!(text.contains("Unlock the keyring, accept its prompt and try again.")); + assert!(text.contains( + "With automatic login, GNOME may have no default keyring yet: create one in Passwords and Keys and make it the default." + )); + } + } + + #[gtk4::test] + fn locked_token_row_shows_recovery_and_retry() { + let settings = MemorySettings::new(); + let page = bound_page(&settings, None); + let imp = page.imp(); + + for error in [SecretError::Locked, SecretError::UnlockDismissed] { + page.show_status(McpStatus::Failed(McpFailure::Keyring(error))); + + let subtitle = imp.status_row.subtitle().expect("the failure status"); + assert!(subtitle.contains("create one in Passwords and Keys and make it the default.")); + assert!(imp.retry_button.is_visible()); + + page.show_status(McpStatus::Off); + + assert_eq!(imp.status_row.subtitle().as_deref(), Some("Off")); + assert!(!imp.retry_button.is_visible()); + } + } + #[test] fn each_failure_has_its_own_sentence() { let failures = [ @@ -1701,6 +1736,7 @@ mod tests { }, McpFailure::Keyring(SecretError::Locked), McpFailure::Keyring(SecretError::ServiceUnavailable { detail: String::new() }), + McpFailure::Keyring(SecretError::PortalUnavailable { detail: String::new() }), McpFailure::NoRandomness, McpFailure::Interrupted(String::new()), ]; @@ -1708,5 +1744,17 @@ mod tests { assert_eq!(texts.len(), failures.len()); assert!(failure_text(&McpFailure::PortInUse(4000)).contains("4000")); + assert_eq!( + status_text(&McpStatus::Failed(McpFailure::Keyring( + SecretError::ServiceUnavailable { detail: String::new() } + ))), + "No keyring is running, so the access token cannot be kept. Start a keyring and try again." + ); + assert_eq!( + status_text(&McpStatus::Failed(McpFailure::Keyring( + SecretError::PortalUnavailable { detail: String::new() } + ))), + "The secret portal is unavailable, so the access token cannot be kept. Check that xdg-desktop-portal and a keyring are running." + ); } } diff --git a/linux/crates/app/src/ui/session_window/connections.rs b/linux/crates/app/src/ui/session_window/connections.rs index 5101608445..45fdc15bc8 100644 --- a/linux/crates/app/src/ui/session_window/connections.rs +++ b/linux/crates/app/src/ui/session_window/connections.rs @@ -1514,7 +1514,11 @@ mod tests { assert_eq!( toasts(), - ["The connection could not be duplicated. The keyring is locked. Unlock it and try again."] + [ + "The connection could not be duplicated. The keyring is locked. Unlock the keyring, accept its \ + prompt and try again. With automatic login, GNOME may have no default keyring yet: create one \ + in Passwords and Keys and make it the default." + ] ); }