Skip to content

chore: reduce noisyness of update cache error#2415

Open
krille-chan wants to merge 1 commit into
mainfrom
krille/reduce-noisyness-of-update-crash
Open

chore: reduce noisyness of update cache error#2415
krille-chan wants to merge 1 commit into
mainfrom
krille/reduce-noisyness-of-update-crash

Conversation

@krille-chan

Copy link
Copy Markdown
Contributor

We really don't need to print the stacktrace here. If the app consumer is interested, they can just set throwOnUpdateFailure to true anyway.

We really don't need to print the
stacktrace here. If the app consumer
is interested, they can just
set throwOnUpdateFailure to true anyway.
@cursor

cursor Bot commented Jul 19, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Logging-only change in a shared cache helper; no change to error handling or return values.

Overview
When a cache refresh fails in requestAndCache, logging is toned down so routine network or persistence errors do not flood warning-level output.

The catch handler no longer captures or logs a stack trace, and the message moves from warning (Logs().w) to verbose (Logs().v) while still recording the error object. Fallback to stale cache when throwOnUpdateFailure is false (the default on calls like getWellknown, getVersions, and getConfig) is unchanged; callers that need failures surfaced can still set throwOnUpdateFailure to true.

Reviewed by Cursor Bugbot for commit 68295f3. Bugbot is set up for automated code reviews on this repo. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.

Fix All in Cursor

Bugbot Autofix prepared fixes for both issues found in the latest run.

  • ✅ Fixed: Log before rethrow
    • Moved the Logs().v call into the stale-cache fallback branch so it only logs when the exception is swallowed, never before rethrow.
  • ✅ Fixed: Missing exception stacktrace
    • Restored catch (error, stackTrace) and passed stackTrace as the third argument to Logs().v.

Create PR

Or push these changes by commenting:

@cursor push 84deda0503
Preview (84deda0503)
diff --git a/lib/src/utils/request_and_cache.dart b/lib/src/utils/request_and_cache.dart
--- a/lib/src/utils/request_and_cache.dart
+++ b/lib/src/utils/request_and_cache.dart
@@ -25,10 +25,9 @@
       final content = await requestFunc();
       await database.cacheCustomObject(cacheKey, toJson(content));
       return content;
-    } catch (error) {
-      Logs().v('Unable to update cache for $cacheKey', error);
-
+    } catch (error, stackTrace) {
       if (!throwOnUpdateFailure && cachedResponse != null) {
+        Logs().v('Unable to update cache for $cacheKey', error, stackTrace);
         return fromJson(cachedResponse.content);
       }
       rethrow;

You can send follow-ups to the cloud agent here.

Reviewed by Cursor Bugbot for commit 68295f3. Configure here.

} catch (error, stackTrace) {
Logs().w('Unable to update cache for $cacheKey', error, stackTrace);
} catch (error) {
Logs().v('Unable to update cache for $cacheKey', error);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Log before rethrow

Medium Severity

Issue: Logs().v runs on every failure, including paths that rethrow, so consumers still get SDK noise they cannot suppress when they handle the exception themselves via throwOnUpdateFailure.
Fix: Call Logs().v only inside the stale-cache fallback branch (when the error is swallowed), not before rethrow.

Fix in Cursor Fix in Web

Triggered by learned rule: Do not log exceptions that are rethrown to the caller

Reviewed by Cursor Bugbot for commit 68295f3. Configure here.

} catch (error, stackTrace) {
Logs().w('Unable to update cache for $cacheKey', error, stackTrace);
} catch (error) {
Logs().v('Unable to update cache for $cacheKey', error);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing exception stacktrace

Low Severity

Issue: The catch logs a caught exception without a stacktrace (catch (error) and Logs().v(..., error) only).
Fix: Use catch (error, stackTrace) and pass stackTrace into Logs().v wherever this failure is logged.

Fix in Cursor Fix in Web

Triggered by learned rule: Always include stacktrace when logging caught exceptions

Reviewed by Cursor Bugbot for commit 68295f3. Configure here.

@codecov

codecov Bot commented Jul 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 59.66%. Comparing base (5c1c48a) to head (68295f3).

Files with missing lines Patch % Lines
lib/src/utils/request_and_cache.dart 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2415   +/-   ##
=======================================
  Coverage   59.66%   59.66%           
=======================================
  Files         161      161           
  Lines       20329    20329           
=======================================
  Hits        12129    12129           
  Misses       8200     8200           
Files with missing lines Coverage Δ
lib/src/utils/request_and_cache.dart 77.77% <0.00%> (ø)

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5c1c48a...68295f3. Read the comment docs.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant