Skip to content

fix: log token cache errors instead of silently swallowing them#193

Merged
jpoehnelt merged 1 commit intogoogleworkspace:mainfrom
Bortlesboat:fix/token-storage-error-logging
Mar 5, 2026
Merged

fix: log token cache errors instead of silently swallowing them#193
jpoehnelt merged 1 commit intogoogleworkspace:mainfrom
Bortlesboat:fix/token-storage-error-logging

Conversation

@Bortlesboat
Copy link

Summary

load_from_disk used four nested if let Ok blocks that silently returned an empty HashMap on any failure. When the encryption key rotated or the cache was corrupted, tokens silently stopped loading and users were forced to re-authenticate with no explanation of what went wrong.

This is a likely contributor to issues like #151 and #137 where users report "credentials saved successfully" but get 401 on all commands.

Changes

  • src/token_storage.rs: Replace nested if let Ok with explicit match arms that log specific warnings to stderr:
    • Decryption failure: warns about key change/corruption, hints to re-auth
    • Invalid UTF-8: warns about encoding issue
    • JSON parse failure: warns about deserialization error
    • File not found: still silent (normal on first run)

Test plan

  • CI: cargo test, cargo clippy, cargo fmt

@changeset-bot
Copy link

changeset-bot bot commented Mar 5, 2026

🦋 Changeset detected

Latest commit: b3a40a1

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 addresses a critical user experience issue where token cache loading failures were silently ignored, leading to users being unable to authenticate without understanding why. By introducing explicit error handling and informative logging, the changes ensure that users receive clear feedback when their token cache is corrupted or inaccessible, guiding them towards a resolution.

Highlights

  • Improved Error Visibility: Replaced silent if let Ok blocks with explicit match statements in load_from_disk to provide clear error messages.
  • Specific Error Logging: Implemented logging to stderr for decryption failures, invalid UTF-8 encoding, and JSON parsing errors during token cache loading.
  • User Guidance: Added a hint to re-authenticate when decryption of the token cache fails, guiding users on how to resolve the issue.
Changelog
  • .changeset/fix-token-storage-error-logging.md
    • Documented the change to log token cache decryption/parse errors instead of silently swallowing them.
  • src/token_storage.rs
    • Refactored the load_from_disk function to replace nested if let Ok statements with explicit match expressions.
    • Added eprintln! calls to log specific warnings for decryption failures, invalid UTF-8 data, and JSON parsing errors.
    • Included a user-friendly hint to re-authenticate when decryption fails.
Activity
  • No human activity has occurred on this pull request yet.
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.

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 significantly improves the error handling within the load_from_disk function by replacing nested if let Ok statements with explicit match arms. This change ensures that specific failures during token cache loading, such as decryption errors, invalid UTF-8, or JSON parsing issues, are now logged to stderr with informative warnings and hints for the user. This addresses the problem of silently failing token loads, which previously led to confusing authentication issues. The .changeset file accurately documents these improvements.

load_from_disk used four nested if-let-Ok blocks that silently
returned an empty HashMap on any failure. When the encryption key
rotated or the cache file was corrupted, tokens silently stopped
loading and users were forced to re-authenticate with no explanation.

Replace with explicit match arms that log specific warnings to
stderr for each failure mode:
- Decryption failure (key changed, corrupted data)
- Invalid UTF-8 in decrypted data
- JSON deserialization failure

File-not-found is still silent since that's normal on first run.
@jpoehnelt jpoehnelt added area: auth cla: yes This human has signed the Contributor License Agreement. complexity: medium Moderate change, some review needed labels Mar 5, 2026
@jpoehnelt jpoehnelt merged commit 9a780d7 into googleworkspace:main Mar 5, 2026
22 checks passed
@codecov
Copy link

codecov bot commented Mar 5, 2026

Codecov Report

❌ Patch coverage is 0% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.17%. Comparing base (473dd30) to head (b3a40a1).
⚠️ Report is 25 commits behind head on main.

Files with missing lines Patch % Lines
src/token_storage.rs 0.00% 20 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #193      +/-   ##
==========================================
- Coverage   56.21%   56.17%   -0.05%     
==========================================
  Files          38       38              
  Lines       13853    13863      +10     
==========================================
  Hits         7788     7788              
- Misses       6065     6075      +10     

☔ 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.

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

Labels

area: auth cla: yes This human has signed the Contributor License Agreement. complexity: medium Moderate change, some review needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants