Skip to content

Add structured logging to silently swallowed catch blocks#4

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1782424306-improve-error-handling
Open

Add structured logging to silently swallowed catch blocks#4
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1782424306-improve-error-handling

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Summary

Several best-effort catch blocks swallowed exceptions with no logging at all — a Redis hiccup, a failed audit write, or a quota-release error would vanish silently, making production diagnosis impossible. This PR injects ILogger<T> into those services and adds structured log calls so every swallowed failure leaves a trace.

What changed (all catches remain non-fatal — only visibility is added):

# RedisCachePurge — cache purge failures were invisible
- catch (Exception) when (!ct.IsCancellationRequested) { }
+ catch (Exception ex) when (!ct.IsCancellationRequested)
+   logger.LogWarning(ex, "Cache purge failed for prefix '{Prefix}'", prefix);

# JobService.TransitionAsync — audit-write failures were invisible
- catch (Exception ex) when (ex is not OperationCanceledException) { }
+ catch (...) { logger.LogWarning(ex, "Audit write failed for upload.{State} on job {JobId}", to, job.Id); }

# QuotaService.ChargeUnitsAsync — Redis metering failures were invisible
- catch { /* best-effort meter */ }
+ catch (Exception ex) { logger.LogWarning(ex, "Quota unit charge failed for project {ProjectId}", projectId); }

# GoogleAccountsService.ExchangeAndStoreAsync — channel lookup failures were invisible
- catch { /* channel lookup is best-effort */ }
+ catch (Exception ex) { logger.LogWarning(ex, "Channel lookup failed during OAuth exchange for project {ProjectId}", projectId); }

# UploadJobHandler — three bare catch blocks for quota release / MarkAccountError
- catch { /* best effort */ }
+ catch (Exception qex) { logger.LogDebug(qex, "Best-effort quota release failed ..."); }
+ catch (Exception aex) { logger.LogWarning(aex, "Best-effort MarkAccountError failed ..."); }

# YouTubeUploadsProviderEndpoints OAuth start — BuildConsentUrlAsync failure was unlogged
+ loggerFactory.CreateLogger("YouTubeUploads.Google.OAuth").LogError(ex, "Google OAuth start failed for project {ProjectId}", projectId.Value);

Test constructors updated to pass NullLogger<T>.Instance for the new parameters. All 234 tests pass.

Link to Devin session: https://app.devin.ai/sessions/0b54f37fe20049d0a218def75b07b0c0
Requested by: @skyp1nus

Inject ILogger into services with bare catch blocks and add
structured log calls so failures leave a diagnostic trail:

- RedisCachePurge: log cache purge failures at Warning
- JobService: log audit-write failures at Warning
- UploadJobHandler: log quota-release and mark-account-error
  failures at Debug/Warning
- YouTubeUploadsProviderEndpoints: log OAuth start failures
- QuotaService: log unit-charge failures at Warning
- GoogleAccountsService: log channel-lookup failures at Warning

All catches remain non-fatal (best-effort swallowing preserved);
the only change is visibility via structured logging.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@skyp1nus skyp1nus self-assigned this Jun 25, 2026
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

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