chore: reduce noisyness of update cache error#2415
Conversation
We really don't need to print the stacktrace here. If the app consumer is interested, they can just set throwOnUpdateFailure to true anyway.
PR SummaryLow Risk Overview The catch handler no longer captures or logs a stack trace, and the message moves from warning ( Reviewed by Cursor Bugbot for commit 68295f3. Bugbot is set up for automated code reviews on this repo. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.
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.
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); |
There was a problem hiding this comment.
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.
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); |
There was a problem hiding this comment.
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.
Triggered by learned rule: Always include stacktrace when logging caught exceptions
Reviewed by Cursor Bugbot for commit 68295f3. Configure here.
Codecov Report❌ Patch coverage is
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
Continue to review full report in Codecov by Harness.
|



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