Skip to content

fix: warn on stderr when discovery cache write fails#191

Open
Bortlesboat wants to merge 1 commit intogoogleworkspace:mainfrom
Bortlesboat:fix/discovery-cache-warning
Open

fix: warn on stderr when discovery cache write fails#191
Bortlesboat wants to merge 1 commit intogoogleworkspace:mainfrom
Bortlesboat:fix/discovery-cache-warning

Conversation

@Bortlesboat
Copy link
Contributor

Summary

The comment on the cache write says "Non-fatal: just warn via stderr-safe approach" but the error was actually assigned to _ and silently discarded. Now prints a warning to stderr with the file path and error, so users can diagnose cache persistence issues.

Changes

  • src/discovery.rs: Replace let _ = e; with eprintln! warning that includes the cache file path and error message

Test plan

  • CI: cargo test, cargo clippy, cargo fmt

@Bortlesboat Bortlesboat requested a review from jpoehnelt as a code owner March 5, 2026 17:31
@changeset-bot
Copy link

changeset-bot bot commented Mar 5, 2026

🦋 Changeset detected

Latest commit: 70361fe

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request improves error visibility by ensuring that failures during the discovery document cache write operation are no longer silently ignored. Instead, a warning is now printed to stderr, providing users with crucial information to diagnose cache persistence issues, such as full disks or permission problems.

Highlights

  • Error Handling: Changed the discovery cache write error handling from silently discarding the error to printing a warning to stderr with the file path and error message.
Changelog
  • .changeset/fix-discovery-cache-warning.md
    • Added a new changeset entry for the discovery cache warning fix.
  • src/discovery.rs
    • Replaced silent error discarding with an eprintln! warning for failed cache writes.
    • Updated the comment for cache writing to reflect the new warning behavior.
Activity
  • No specific activity has been recorded for this pull request since its creation.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@Bortlesboat Bortlesboat force-pushed the fix/discovery-cache-warning branch from 0bce00a to cbaab50 Compare March 5, 2026 17:34
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly addresses an issue where a cache write error was silently discarded. Logging the error to stderr is the right approach. However, the current implementation of the eprintln! macro mixes positional and named format arguments, which will cause a compilation error. I've left a specific comment with a suggested fix. With that change, the PR should be good to merge.

@jpoehnelt jpoehnelt added area: discovery cla: yes This human has signed the Contributor License Agreement. complexity: low Small, straightforward change labels Mar 5, 2026
@googleworkspace-bot
Copy link
Contributor

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request addresses an issue where an error during the discovery cache write was silently discarded. The change correctly implements the intended behavior by printing a warning to stderr, including the file path and the error message. This will help users diagnose potential cache persistence issues. The implementation is sound and aligns with the project's existing error handling patterns.

@codecov
Copy link

codecov bot commented Mar 5, 2026

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 57.53%. Comparing base (473dd30) to head (f2f9e74).
⚠️ Report is 26 commits behind head on main.

Files with missing lines Patch % Lines
src/discovery.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #191      +/-   ##
==========================================
+ Coverage   56.21%   57.53%   +1.32%     
==========================================
  Files          38       38              
  Lines       13853    14185     +332     
==========================================
+ Hits         7788     8162     +374     
+ Misses       6065     6023      -42     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Bortlesboat Bortlesboat force-pushed the fix/discovery-cache-warning branch from f2f9e74 to 70361fe Compare March 6, 2026 00:30
@google-cla google-cla bot added cla: no This human has *not* signed the Contributor License Agreement. and removed cla: yes This human has signed the Contributor License Agreement. labels Mar 6, 2026
@googleworkspace-bot
Copy link
Contributor

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request fixes an issue where an error when writing the discovery document cache was silently ignored. The change introduces a warning message to stderr, which is a good improvement for diagnostics. I've added one comment regarding a potential panic when writing to stderr, suggesting a more robust way to handle the warning in a 'non-fatal' manner.

Comment on lines 245 to 247
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);
}
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);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: discovery cla: no This human has *not* signed the Contributor License Agreement. complexity: low Small, straightforward change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants