Skip to content

Adjust logs#1006

Merged
elie222 merged 3 commits intomainfrom
chore/logs
Nov 24, 2025
Merged

Adjust logs#1006
elie222 merged 3 commits intomainfrom
chore/logs

Conversation

@elie222
Copy link
Owner

@elie222 elie222 commented Nov 24, 2025

Adjust logger error serialization in apps/web/utils/logger.serializeError and log full webhook errors in apps/web/utils/webhook/error-handler.handleWebhookError

Replace manual property copying with object spread plus explicit name, message, and stack in serializeError, remove isRecord, update webhook error logging to pass the raw error, and add a Vitest suite validating error output across varied shapes.

📍Where to Start

Start with serializeError in logger.ts, then review the logging change in webhook/error-handler.ts, and validate behavior via logger.test.ts.


Macroscope summarized 7c92712.

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced error serialization to capture more comprehensive error details without incomplete representations.
    • Updated error logging for unhandled webhook errors for improved visibility.
  • Tests

    • Added extensive test coverage for error serialization across various error scenarios.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link

vercel bot commented Nov 24, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
inbox-zero Ready Ready Preview Nov 24, 2025 2:57pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 24, 2025

Walkthrough

The pull request enhances error serialization and logging capabilities. A new comprehensive test suite validates the logger utility's error serialization across diverse error shapes. The serializeError function is refactored to use object spreading with explicit field normalization. Webhook error handling is updated to log raw error objects instead of stringified messages. The version is bumped to v2.20.22.

Changes

Cohort / File(s) Summary
Test Suite
apps/web/utils/logger.test.ts
New comprehensive test suite for createScopedLogger, validating error serialization across various shapes (simple Error, custom properties, nested structures, arrays, axios-like formats, deeply nested errors) with console.error spy assertions.
Error Serialization & Logging
apps/web/utils/logger.ts, apps/web/utils/webhook/error-handler.ts
serializeError function simplified to spread error object and explicitly normalize name, message, and stack fields; webhook error handler changed to log raw error objects instead of stringified messages.
Version Update
version.txt
Version bumped from v2.20.21 to v2.20.22.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Focus areas: Verify that the new test suite comprehensively covers the serialization behavior; confirm that the serializeError refactoring correctly handles all error object shapes and edge cases; validate that logging raw error objects in the webhook handler aligns with intended downstream processing and doesn't break existing log consumers.

Possibly related PRs

  • Adjust logs #956: Changes error-logging to emit raw/error objects instead of formatted strings, aligning with the main PR's shift toward logging raw errors in the webhook handler.
  • Adjust logs #1003: Directly modifies the same logger utility file (apps/web/utils/logger.ts), altering error serialization and normalization helpers.
  • Adjust outlook webhook logger #916: Updates webhook modules to use the scoped Logger and propagate it through processing paths, complementing the webhook error-handler changes.

Poem

🐰 Errors now tell their truest tale,
No objects hidden, no details pale,
With spreading spreads and fields set right,
Our logs now shine with crystal light!
v2.20.22 hops forward true,
Error serialization—totally renewed!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title 'Adjust logs' is vague and generic, failing to specify what aspect of logging is being adjusted or why, making it unclear for developers scanning history. Consider a more descriptive title like 'Improve error serialization in logger' or 'Fix error object logging in webhook handler' to clearly indicate the main purpose of the changes.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/logs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
apps/web/utils/logger.ts (1)

139-150: LGTM! Clean error serialization approach.

The spread operator combined with explicit field assignment correctly captures both custom enumerable properties (like statusCode, code) and standard Error properties (name, message, stack). This ensures rich error context is preserved in production logs.

One minor edge case: properties added with Object.defineProperty(..., {enumerable: false}) won't be captured by the spread. If you want to verify the spread behavior handles your common error shapes correctly, you could run:

#!/bin/bash
# Find examples of Error instances with custom properties to verify spread behavior
rg -n -C3 --type=ts 'new Error\(' | rg -A5 'statusCode|code|response|config'
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 64c2576 and 7c92712.

📒 Files selected for processing (4)
  • apps/web/utils/logger.test.ts (1 hunks)
  • apps/web/utils/logger.ts (1 hunks)
  • apps/web/utils/webhook/error-handler.ts (1 hunks)
  • version.txt (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: cubic · AI code reviewer
🔇 Additional comments (3)
version.txt (1)

1-1: LGTM!

Standard version bump to v2.20.22.

apps/web/utils/webhook/error-handler.ts (1)

37-40: LGTM!

Logging the raw error object instead of extracting the message aligns well with the improved error serialization in logger.ts. The logger will now capture richer error context including custom properties like status codes and error codes.

apps/web/utils/logger.test.ts (1)

1-182: LGTM! Comprehensive error serialization test coverage.

The test suite thoroughly validates that various error shapes are serialized without [object Object] artifacts while preserving important fields. The coverage includes simple errors, nested structures, arrays, and axios-like formats.

The comment on lines 56-57 correctly notes that Error instances show only their message in console logs. This is expected behavior—the console logger (used in development) converts Error instances to messages for readability via processErrorsInObject, while the Axiom logger (used in production) preserves custom properties in the errorFull field via serializeError.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 4 files

Prompt for AI agents (all 1 issues)

Understand the root cause of the following 1 issues and fix them.


<file name="apps/web/utils/logger.test.ts">

<violation number="1" location="apps/web/utils/logger.test.ts:28">
console.error is spied on but never restored, so later tests run with a mocked console.error and lose real error output. Add an afterEach (or enable vi.restoreAllMocks) to clean up the spy after each test.</violation>
</file>

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR


beforeEach(() => {
vi.clearAllMocks();
consoleErrorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Nov 24, 2025

Choose a reason for hiding this comment

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

console.error is spied on but never restored, so later tests run with a mocked console.error and lose real error output. Add an afterEach (or enable vi.restoreAllMocks) to clean up the spy after each test.

Prompt for AI agents
Address the following comment on apps/web/utils/logger.test.ts at line 28:

<comment>console.error is spied on but never restored, so later tests run with a mocked console.error and lose real error output. Add an afterEach (or enable vi.restoreAllMocks) to clean up the spy after each test.</comment>

<file context>
@@ -0,0 +1,182 @@
+
+  beforeEach(() =&gt; {
+    vi.clearAllMocks();
+    consoleErrorSpy = vi.spyOn(console, &quot;error&quot;).mockImplementation(() =&gt; {});
+  });
+
</file context>
Fix with Cubic

@elie222 elie222 merged commit 027f420 into main Nov 24, 2025
19 checks passed
@elie222 elie222 deleted the chore/logs branch November 24, 2025 16:05
@coderabbitai coderabbitai bot mentioned this pull request Dec 5, 2025
@coderabbitai coderabbitai bot mentioned this pull request Dec 21, 2025
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

Comments