Skip to content

fix(api): stop logging raw Error objects in 4 catch blocks [BUG-113] - #228

Open
Morenikeoa wants to merge 1 commit into
dcccrypto:mainfrom
Morenikeoa:fix/raw-error-logging
Open

fix(api): stop logging raw Error objects in 4 catch blocks [BUG-113]#228
Morenikeoa wants to merge 1 commit into
dcccrypto:mainfrom
Morenikeoa:fix/raw-error-logging

Conversation

@Morenikeoa

Copy link
Copy Markdown

Bug

Four catch blocks log the raw Error object (or an untruncated .message/.stack) directly into structured logging calls, instead of following the truncateErrorMessage(...) convention this codebase already established (see BUG-007, PR #216):

  • src/index.ts's shutdown() catch ({ error: err }) and the uncaughtException handler ({ error: err.message, stack: err.stack }, untruncated).
  • src/routes/ws.ts's WS message-handler catch ({ ip: client.ip, error: err }) — the one outlier among ~9 other catches in this same file, all of which already extract err.message.
  • src/routes/chart.ts's getTopPool and fetchOhlcv catches ({ mint, err } / { poolAddress, err }).

A raw Error object in a log call carries an unbounded stack trace, and depending on the logger/transport's serialization, can blow up log line size or fail to serialize cleanly at all (circular refs, non-enumerable properties).

Fix

  • ws.ts and chart.ts's outlier catches now extract err instanceof Error ? err.message : String(err), matching their own file's existing pattern (ws.ts) or the codebase-wide truncateErrorMessage(...) pattern (chart.ts, which had no prior local convention to match).
  • index.ts's uncaughtException handler now mirrors the exact truncation pattern its own generic Hono error handler already uses ~190 lines above it: message capped at 120 chars via truncateErrorMessage, stack capped at 500. The shutdown() catch immediately above it had the identical raw-object pattern, so it's fixed the same way as part of the same change.

index.ts itself has no unit tests anywhere in this codebase (it has real side effects on import — this is why BUG-102 extracted shutdown.ts separately), so there's no test to add for that file's two catches; the fix there is a direct, low-risk mirror of an already-tested-by-precedent in-file pattern.

Test plan

  • Added an error logging (BUG-113) block to tests/routes/chart.test.ts: forces getTopPool's and fetchOhlcv's fetch calls to reject, asserts the logged error field is a string containing the original message rather than the raw Error object.
  • Added tests/routes/ws-error-logging.test.ts: spins up a real WS server, sends a malformed (non-JSON) message to trigger the message-handler catch, asserts the logged error field is a string.
  • Verified all 3 new/changed assertions are genuine regressions: reverted src/index.ts/src/routes/ws.ts/src/routes/chart.ts via git stash, confirmed the new tests fail against the unfixed code, restored the fix.
  • Full suite passes (297/298 — the 1 pre-existing failure is unrelated to this change, in adl.test.ts).
  • tsc --noEmit clean.

index.ts's shutdown() catch + uncaughtException handler, ws.ts's WS
message-handler catch, and chart.ts's getTopPool/fetchOhlcv catches all
logged the raw Error object (or untruncated .message/.stack) instead of
following the truncateErrorMessage(...) convention already established
everywhere else in this codebase (see BUG-007). A raw Error object in a
structured-logging call can carry an unbounded stack trace and, on some
logger/transport configurations, fail to serialize cleanly at all.

index.ts's uncaughtException handler now mirrors the truncation pattern
its own generic Hono error handler already uses two functions above it
(message capped at 120 chars, stack at 500). The shutdown() catch right
next to it had the same raw-object pattern, so it's fixed too.
@vercel

vercel Bot commented Jun 26, 2026

Copy link
Copy Markdown

@Princessdada is attempting to deploy a commit to the Khubair Nasir's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Morenikeoa, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 37 minutes and 35 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e7f0f6ef-127d-4f91-b85d-7205ce7ee8e6

📥 Commits

Reviewing files that changed from the base of the PR and between b2751f4 and 7c7f809.

📒 Files selected for processing (5)
  • src/index.ts
  • src/routes/chart.ts
  • src/routes/ws.ts
  • tests/routes/chart.test.ts
  • tests/routes/ws-error-logging.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

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