fix: prevent arbitrary error .code from leaking into onError handler#1818
fix: prevent arbitrary error .code from leaking into onError handler#1818eL1fe wants to merge 1 commit intoelysiajs:mainfrom
Conversation
When a handler throws an error with a .code property (e.g. AxiosError with code "ECONNREFUSED"), Elysia passed that value as the error code to onError instead of "UNKNOWN". This broke error handling for anyone using libraries like axios, node:fs, etc. Root cause: codegen checked error.code before error[ERROR_CODE] (the Elysia-specific symbol). Fixed by: 1. Adding [ERROR_CODE] symbol to all built-in error classes 2. Using only error[ERROR_CODE] in codegen/dynamic handler, with "UNKNOWN" as the sole fallback Fixes elysiajs#1412
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
WalkthroughThe changes introduce a symbol-based property ( Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
Summary
.codeproperty (e.g. AxiosError, node:fs errors) leaked their.codeintoonErrorhandler instead of"UNKNOWN"error.codebeforeerror[ERROR_CODE](Elysia's symbol)Problem
This breaks error handling for anyone using libraries that throw errors with a
.codeproperty (axios, node:fs, undici, etc).Changes
src/error.ts: add[ERROR_CODE]symbol to all built-in error classes (NotFoundError,ValidationError,ParseError,InternalServerError,InvalidCookieSignature)src/compose.ts: use onlyerror[ERROR_CODE] ?? "UNKNOWN"in codegen (droperror.codefallback)src/dynamic-handle.ts: same change for dynamic/JIT handler pathTest plan
.codenow correctly show"UNKNOWN"in onErrorNOT_FOUND,VALIDATION,PARSE, etc.) still work correctlyElysia.error()still work correctlyaot: false) modes testedFixes #1412
Summary by CodeRabbit