Skip to content
Closed
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
10 changes: 10 additions & 0 deletions .changeset/fix-discovery-cache-warning.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@anthropic/gws": patch
---

Warn on stderr when discovery cache write fails

Previously, the error from writing the discovery document cache was
silently discarded (`let _ = e`). Now prints a warning to stderr so
users are aware their cache is not persisting (e.g., due to disk full
or permission issues).
5 changes: 2 additions & 3 deletions src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,9 @@ pub async fn fetch_discovery_document(
alt_resp.text().await?
};

// Write to cache
// Write to cache (non-fatal — warn if it fails)
if let Err(e) = std::fs::write(&cache_file, &body) {
// Non-fatal: just warn via stderr-safe approach
let _ = e;
eprintln!("warning: failed to write discovery cache to {}: {}", cache_file.display(), e);
}
Comment on lines 245 to 247
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

While eprintln! is a good step up from silently ignoring the error, it can panic if writing to stderr fails (e.g., if the pipe is closed). Given the operation is described as 'non-fatal', a panic would be an undesirable outcome. To create a truly 'stderr-safe' warning that won't panic, it's better to use writeln! with std::io::stderr() and ignore the Result. This ensures that a failure to write the warning doesn't crash the application.

Suggested change
if let Err(e) = std::fs::write(&cache_file, &body) {
// Non-fatal: just warn via stderr-safe approach
let _ = e;
eprintln!("warning: failed to write discovery cache to {}: {}", cache_file.display(), e);
}
if let Err(e) = std::fs::write(&cache_file, &body) {
use std::io::Write;
let _ = writeln!(std::io::stderr(), "warning: failed to write discovery cache to {}: {}", cache_file.display(), e);
}


let doc: RestDescription = serde_json::from_str(&body)?;
Expand Down