fix(api): stop logging raw Error objects in 4 catch blocks [BUG-113] - #228
fix(api): stop logging raw Error objects in 4 catch blocks [BUG-113]#228Morenikeoa wants to merge 1 commit into
Conversation
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.
|
@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. |
|
Warning Review limit reached
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 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Bug
Four catch blocks log the raw
Errorobject (or an untruncated.message/.stack) directly into structured logging calls, instead of following thetruncateErrorMessage(...)convention this codebase already established (see BUG-007, PR #216):src/index.ts'sshutdown()catch ({ error: err }) and theuncaughtExceptionhandler ({ 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 extracterr.message.src/routes/chart.ts'sgetTopPoolandfetchOhlcvcatches ({ mint, err }/{ poolAddress, err }).A raw
Errorobject 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.tsandchart.ts's outlier catches now extracterr instanceof Error ? err.message : String(err), matching their own file's existing pattern (ws.ts) or the codebase-widetruncateErrorMessage(...)pattern (chart.ts, which had no prior local convention to match).index.ts'suncaughtExceptionhandler now mirrors the exact truncation pattern its own generic Hono error handler already uses ~190 lines above it: message capped at 120 chars viatruncateErrorMessage, stack capped at 500. Theshutdown()catch immediately above it had the identical raw-object pattern, so it's fixed the same way as part of the same change.index.tsitself has no unit tests anywhere in this codebase (it has real side effects on import — this is why BUG-102 extractedshutdown.tsseparately), 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
error logging (BUG-113)block totests/routes/chart.test.ts: forcesgetTopPool's andfetchOhlcv'sfetchcalls to reject, asserts the loggederrorfield is a string containing the original message rather than the rawErrorobject.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 loggederrorfield is a string.src/index.ts/src/routes/ws.ts/src/routes/chart.tsviagit stash, confirmed the new tests fail against the unfixed code, restored the fix.adl.test.ts).tsc --noEmitclean.