Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions .changeset/fix-token-dir-error-propagation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gws": patch
---

Fix auth error propagation: properly propagate errors when token directory creation or permission setting fails, instead of silently ignoring them
23 changes: 21 additions & 2 deletions src/token_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,30 @@ impl EncryptedTokenStorage {
let encrypted = crate::credential_store::encrypt(json.as_bytes())?;

if let Some(parent) = self.file_path.parent() {
let _ = tokio::fs::create_dir_all(parent).await;
tokio::fs::create_dir_all(parent).await.map_err(|e| {
anyhow::anyhow!(
"Failed to create token directory '{}': {}",
sanitize_for_terminal(&parent.display().to_string()),
e
)
})?;
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
let _ = std::fs::set_permissions(parent, std::fs::Permissions::from_mode(0o700));
let parent_path = parent.to_path_buf();
let parent_display = parent.display().to_string();
tokio::task::spawn_blocking(move || {
std::fs::set_permissions(&parent_path, std::fs::Permissions::from_mode(0o700))
})
.await
.map_err(|join_err| anyhow::anyhow!("Failed to run set_permissions task: {join_err}"))?
.map_err(|io_err| {
anyhow::anyhow!(
"Failed to set permissions on token directory '{}': {}",
sanitize_for_terminal(&parent_display),
io_err
)
})?;
}
}

Expand Down
Loading