Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions linux/changelog.d/4234.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Locked-keyring errors omitted the steps to create a default keyring.
15 changes: 10 additions & 5 deletions linux/crates/app/src/services/secret_save_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
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.")
Expand All @@ -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 {
Expand Down
24 changes: 21 additions & 3 deletions linux/crates/app/src/ui/assistant/error_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
),
Expand Down Expand Up @@ -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}"
);
}
}
}
3 changes: 2 additions & 1 deletion linux/crates/app/src/ui/error_text/saved_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())),
Expand Down
14 changes: 10 additions & 4 deletions linux/crates/app/src/ui/error_text/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
Expand Down
54 changes: 51 additions & 3 deletions linux/crates/app/src/ui/preferences_dialog/mcp_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
Expand Down Expand Up @@ -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 = [
Expand All @@ -1701,12 +1736,25 @@ 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()),
];
let texts: std::collections::HashSet<String> = failures.iter().map(failure_text).collect();

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."
);
}
}
6 changes: 5 additions & 1 deletion linux/crates/app/src/ui/session_window/connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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."
]
);
}

Expand Down
Loading