Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (4)
WalkthroughAdds CHANGELOG entry for 1.4.22; replaces a WebSocket example with an HTTP POST example; introduces ValueErrorWithSummary and updates error mapping; converts a handler type alias to an interface; tightens Bun routing guard; changes mount/path handling and short-circuits mount via an early mount hook; adds tests and logging. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant DynamicHandle
participant HooksMount as hooks.config.mount
participant BodyParser
participant Handler
Client->>DynamicHandle: HTTP request
alt hooks.config.mount present
DynamicHandle->>HooksMount: invoke mount(request)
HooksMount-->>DynamicHandle: Response (short-circuit)
DynamicHandle-->>Client: return mount response
else no mount hook
DynamicHandle->>BodyParser: parse body
BodyParser-->>DynamicHandle: parsed body
DynamicHandle->>Handler: route to handler with parsed body
Handler-->>DynamicHandle: handler response
DynamicHandle-->>Client: return handler response
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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 |
commit: |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
example/a.ts (1)
25-39: Consider type narrowing for safer status code extraction.The status code logic handles cases where
error.statusmight be a string or invalid number. However, casting withNumber()on non-numeric strings yieldsNaN, which then falls back to500via|| 500. This works but could be clearer.🔎 Slightly cleaner approach
default: { - const statusCode = - "status" in error - ? (typeof error.status === "number" ? error.status : Number(error.status)) || 500 - : 500 + let statusCode = 500 + if ("status" in error && typeof error.status === "number") { + statusCode = error.status + } let errMsg = "An error occurred"
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
CHANGELOG.mdexample/a.tssrc/error.ts
🧰 Additional context used
🧬 Code graph analysis (1)
src/error.ts (1)
src/index.ts (2)
mapValueError(8224-8224)error(3088-3128)
🔇 Additional comments (5)
CHANGELOG.md (1)
1-4: LGTM!The changelog entry accurately documents the bug fix for missing
summarytypes onValueError, which corresponds to the newValueErrorWithSummaryinterface introduced insrc/error.ts.src/error.ts (4)
47-49: LGTM!Formatting change improves readability.
159-161: LGTM!The new
ValueErrorWithSummaryinterface cleanly extendsValueErrorwith an optionalsummaryfield, addressing the type-safety issue mentioned in the changelog.
487-487: LGTM!Return type correctly updated to
ValueErrorWithSummary[]to reflect the mapped error structure.
599-601: LGTM!Safe access pattern correctly guards against undefined
valueErrorbefore callingmapValueError, avoiding potential runtime errors.
| export const mapValueError = (error: ValueError): ValueErrorWithSummary => { | ||
| if (!error) return error | ||
|
|
||
| let { message, path, value, type } = error |
There was a problem hiding this comment.
Type signature inconsistency with runtime guard.
The parameter is typed as ValueError (non-nullable), but line 164 guards against falsy values and returns error (potentially undefined). This creates a mismatch: the return type is ValueErrorWithSummary, but the function can actually return undefined.
Consider either:
- Updating the signature to reflect nullable input/output:
(error: ValueError | undefined): ValueErrorWithSummary | undefined - Removing the guard if callers are guaranteed to pass non-null values
🔎 Option 1: Reflect nullable types
-export const mapValueError = (error: ValueError): ValueErrorWithSummary => {
- if (!error) return error
+export const mapValueError = (error: ValueError | undefined): ValueErrorWithSummary | undefined => {
+ if (!error) return undefined🤖 Prompt for AI Agents
In src/error.ts around lines 163 to 166, the function mapValueError is typed to
accept a non-nullable ValueError but contains a runtime guard that returns the
(possibly undefined) error, causing a signature mismatch; update the function
signature to accept and return nullable types like (error: ValueError |
undefined): ValueErrorWithSummary | undefined, or if callers never pass
undefined, remove the guard and keep the non-nullable signature—choose one
approach and adjust the type annotations accordingly so runtime behavior matches
the TypeScript types.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/type-system/utils.ts`:
- Around line 148-149: Remove the debug console.log call that prints detection
results; specifically delete the line console.log(result, extension) in
src/type-system/utils.ts (inside the file type validation routine) so the file
type detection no longer logs result and extension for every validation before
merging.
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
CHANGELOG.mdexample/a.tssrc/adapter/bun/index.tssrc/adapter/utils.tssrc/compose.tssrc/type-system/utils.ts
💤 Files with no reviewable changes (1)
- src/compose.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- CHANGELOG.md
🔇 Additional comments (3)
src/adapter/bun/index.ts (1)
86-87: LGTM! Stricter check forsystemRouteropt-out.The change from
!app.config.systemRouterto=== falseis more intentional—only an explicitfalsedisables the system router. WhensystemRouterisundefined, routing now activates ifaotis enabled, which is a sensible default.src/adapter/utils.ts (1)
139-146: LGTM!Converting the type alias to an interface is a clean refactor. Interfaces provide better error messages and support declaration merging if needed in the future.
example/a.ts (1)
1-3: LGTM!The simplified example is clean and demonstrates basic Elysia usage. This also resolves the previous review feedback about unused
error.detailby removing the complex error handling code entirely.
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/index.ts (1)
5616-5626: Fix mount path normalization before computingfullPath.length(breaksmount('foo', ...)with prefix).If a caller passes
mount('problems-domain', ...)(no leading/), routing will normalize to/<...>later, butfullPath/lengthwill be computed from the unnormalized string, sopath.slice(length)strips the wrong segment.Proposed fix
- const fullPath = - typeof path === 'string' && this.config.prefix - ? this.config.prefix + path - : path - - const length = fullPath.length - (path.endsWith('*') ? 1 : 0) + const mountPath = path.charCodeAt(0) === 47 ? path : `/${path}` + const fullPath = this.config.prefix ? this.config.prefix + mountPath : mountPath + const length = fullPath.length - (mountPath.endsWith('*') ? 1 : 0) const handler: Handler = ({ request, path }) => handle( new Request( replaceUrlPath(request.url, path.slice(length) || '/'), {
🤖 Fix all issues with AI agents
In `@example/a.ts`:
- Around line 1-18: Remove the noisy console.log from the request handler used
to build sdkApp: inside the callback passed to new
Elysia(...).mount('/problems-domain', (request) => { ... }) delete the
console.log(request.url) line (or move it outside the handler to a demo-level
log) so the handler returns only Response.json({ path: new
URL(request.url).pathname }) without printing the URL; leave Elysia, sdkApp and
the rest of the example unchanged.
In `@src/utils.ts`:
- Around line 30-38: The replaceUrlPath function breaks for short hosts because
it uses a hardcoded indexOf('/', 11); update it to locate the path start in a
scheme-aware way (find "://", then search for the next '/' after the host: use
url.indexOf('://') to compute hostStart = index + 3 and then pathStartIndex =
url.indexOf('/', hostStart)); if pathStartIndex === -1 treat the URL as having
no path (use the whole url as base before adding pathname) and preserve any
query by locating '?' relative to pathStartIndex or host end; keep the existing
pathname leading-slash logic (pathname.charCodeAt(0) === 47) and ensure you
build the final string using the computed base, the normalized pathname, and any
query fragment.
🧹 Nitpick comments (1)
test/core/mount.test.ts (1)
140-172: Nice coverage for mount path stripping with and without prefix.This directly exercises the
fullPath.lengthslicing regression scenario.Consider adding a third test for
mount('problems-domain', ...)(no leading/) if that’s intended to be supported, to lock in the normalization behavior.
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
CHANGELOG.mdexample/a.tssrc/adapter/bun/compose.tssrc/index.tssrc/utils.tstest/core/mount.test.ts
✅ Files skipped from review due to trivial changes (1)
- src/adapter/bun/compose.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- CHANGELOG.md
🧰 Additional context used
🧬 Code graph analysis (2)
test/core/mount.test.ts (1)
src/index.ts (2)
Elysia(190-8185)Elysia(8187-8187)
example/a.ts (1)
src/index.ts (2)
Elysia(190-8185)Elysia(8187-8187)
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
| export const replaceUrlPath = (url: string, pathname: string) => { | ||
| const urlObject = new URL(url) | ||
| urlObject.pathname = pathname | ||
| return urlObject.toString() | ||
| const pathStartIndex = url.indexOf('/', 11) | ||
| const queryIndex = url.indexOf('?', pathStartIndex) | ||
|
|
||
| if (queryIndex === -1) | ||
| return `${url.slice(0, pathStartIndex)}${pathname.charCodeAt(0) === 47 ? '' : '/'}${pathname}` | ||
|
|
||
| return `${url.slice(0, pathStartIndex)}${pathname.charCodeAt(0) === 47 ? '' : '/'}${pathname}${url.slice(queryIndex)}` | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
find . -name "src/utils.ts" -type f | head -1Repository: elysiajs/elysia
Length of output: 41
🏁 Script executed:
cat -n src/utils.ts | sed -n '25,45p'Repository: elysiajs/elysia
Length of output: 995
🏁 Script executed:
rg -n --type=ts -C2 'replaceUrlPath\s*\(' --max-count=20Repository: elysiajs/elysia
Length of output: 543
🏁 Script executed:
sed -n '5570,5590p' src/index.tsRepository: elysiajs/elysia
Length of output: 662
🏁 Script executed:
sed -n '5620,5635p' src/index.tsRepository: elysiajs/elysia
Length of output: 580
🏁 Script executed:
node <<'EOF'
// Test the buggy logic
const replaceUrlPath = (url, pathname) => {
const pathStartIndex = url.indexOf('/', 11)
console.log(`URL: ${url}`)
console.log(` pathStartIndex: ${pathStartIndex}`)
const queryIndex = url.indexOf('?', pathStartIndex)
if (queryIndex === -1)
return `${url.slice(0, pathStartIndex)}${pathname.charCodeAt(0) === 47 ? '' : '/'}${pathname}`
return `${url.slice(0, pathStartIndex)}${pathname.charCodeAt(0) === 47 ? '' : '/'}${pathname}${url.slice(queryIndex)}`
}
// Test case 1: short hostname
console.log('\n=== Test 1: Short hostname ===')
console.log('Result:', replaceUrlPath('http://a/original', '/new'))
// Test case 2: localhost
console.log('\n=== Test 2: localhost ===')
console.log('Result:', replaceUrlPath('http://localhost/original', '/new'))
// Test case 3: empty pathname
console.log('\n=== Test 3: Empty pathname ===')
console.log('Result:', replaceUrlPath('http://localhost/original', ''))
// Test case 4: with query string
console.log('\n=== Test 4: With query string ===')
console.log('Result:', replaceUrlPath('http://localhost/original?foo=bar', '/new'))
EOFRepository: elysiajs/elysia
Length of output: 513
replaceUrlPath: indexOf('/', 11) returns -1 for short hosts and corrupts URLs.
The hardcoded index 11 assumes the host is always at least 11 characters long. For short hostnames like http://a/path, the first / is at index 8, so indexOf('/', 11) returns -1. This causes url.slice(0, -1) to remove the last character instead of slicing correctly, corrupting the URL (e.g., http://a/original becomes http://a/origina/new).
Use a scheme-aware approach to find the path start safely:
Proposed fix
export const replaceUrlPath = (url: string, pathname: string) => {
- const pathStartIndex = url.indexOf('/', 11)
- const queryIndex = url.indexOf('?', pathStartIndex)
+ const schemeSep = url.indexOf('://')
+ const hostStart = schemeSep === -1 ? 0 : schemeSep + 3
+ const pathStartIndex = url.indexOf('/', hostStart)
+ const safePathStartIndex = pathStartIndex === -1 ? url.length : pathStartIndex
+ const queryIndex = url.indexOf('?', safePathStartIndex)
+
+ const nextPath = pathname && pathname.charCodeAt(0) === 47 ? pathname : `/${pathname || ''}`
- if (queryIndex === -1)
- return `${url.slice(0, pathStartIndex)}${pathname.charCodeAt(0) === 47 ? '' : '/'}${pathname}`
+ if (queryIndex === -1) return `${url.slice(0, safePathStartIndex)}${nextPath}`
- return `${url.slice(0, pathStartIndex)}${pathname.charCodeAt(0) === 47 ? '' : '/'}${pathname}${url.slice(queryIndex)}`
+ return `${url.slice(0, safePathStartIndex)}${nextPath}${url.slice(queryIndex)}`
}🤖 Prompt for AI Agents
In `@src/utils.ts` around lines 30 - 38, The replaceUrlPath function breaks for
short hosts because it uses a hardcoded indexOf('/', 11); update it to locate
the path start in a scheme-aware way (find "://", then search for the next '/'
after the host: use url.indexOf('://') to compute hostStart = index + 3 and then
pathStartIndex = url.indexOf('/', hostStart)); if pathStartIndex === -1 treat
the URL as having no path (use the whole url as base before adding pathname) and
preserve any query by locating '?' relative to pathStartIndex or host end; keep
the existing pathname leading-slash logic (pathname.charCodeAt(0) === 47) and
ensure you build the final string using the computed base, the normalized
pathname, and any query fragment.
There was a problem hiding this comment.
yeah don't worry, invalid URL cannot reach this part of the code
There was a problem hiding this comment.
@SaltyAom, understood! If there's upstream validation ensuring only well-formed URLs reach replaceUrlPath, then the hardcoded offset is safe.
✏️ Learnings added
Learnt from: SaltyAom
Repo: elysiajs/elysia PR: 1657
File: src/utils.ts:30-38
Timestamp: 2026-01-14T04:50:53.210Z
Learning: The `replaceUrlPath` function in `src/utils.ts` assumes valid, well-formed URLs as input because upstream validation prevents invalid or malformed URLs from reaching this code path.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Fix all issues with AI agents
In `@CHANGELOG.md`:
- Line 1: The changelog header "# 1.4.22" is missing the release date and should
follow the existing format; update the header string to include the release date
(e.g., change "# 1.4.22" to "# 1.4.22 - <RELEASE DATE>") so it matches other
entries like "# 1.4.21 - 4 Jan 2026".
In `@example/a.ts`:
- Around line 3-5: The function mountedHandler is declared but never used and
duplicates the inline request handler; either remove the unused function
mountedHandler or replace the inline handler passed to .mount(...) with a
reference to mountedHandler so the named function is used instead of a
duplicate; update any imports/exports if you remove it and run a quick lint to
ensure no unused-symbol warnings remain.
In `@src/dynamic-handle.ts`:
- Around line 117-120: The mount handler return is not awaited which prevents
async errors from hooks.config.mount being caught by the surrounding catch
block; update the early-return to await the mount invocation (i.e., return await
hooks.config.mount(request)) and remove the unnecessary // `@ts-ignore`
annotations by fixing the type for hooks.config to include an optional mount:
(req: Request) => Promise<Response> | Response so TypeScript recognizes
hooks.config.mount as a possibly-async function.
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
CHANGELOG.mdexample/a.tssrc/dynamic-handle.tstest/core/mount.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- test/core/mount.test.ts
🧰 Additional context used
🧬 Code graph analysis (1)
example/a.ts (1)
src/index.ts (2)
Elysia(190-8185)Elysia(8187-8187)
🔇 Additional comments (3)
example/a.ts (1)
7-9: Example demonstratesaot: falsemount behavior correctly.The mount usage aligns with the test cases in
test/core/mount.test.tsthat verify body handling withaot: false. Consider using the namedmountedHandlerfunction (if retained) for clarity, or removing it entirely.CHANGELOG.md (1)
2-6: LGTM!The bug fix entries are well-documented with appropriate issue references and clear descriptions that align with the code changes in this PR.
src/dynamic-handle.ts (1)
114-120: LGTM! Correctly placed early return for mount handlers.The mount check is properly positioned after handler resolution but before body parsing, correctly implementing the "skip body parsing on mount with dynamic mode" fix. The
hooksassignment before the early return ensures thefinallyblock can still accesshooks.afterResponse.
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@example/a.ts`:
- Around line 3-18: The Elysia app chain and .post() call are left unterminated
causing a parse error; close the route options and callback by adding the
missing closing braces/parentheses and finish the Elysia chain (e.g., close the
.post(...) call, then call .listen(...) or start the server) so the file ends
with a complete expression; specifically update the code around the Elysia
instance and the "/create-post" route (the new Elysia() instantiation and its
.post handler) to include the missing closing brace/parenthesis and a server
startup call such as .listen(3000) or equivalent, then add the terminating
semicolon.
- Line 1: The file uses t.Object, t.String, and t.Number but never imports t;
add an import that brings TypeBox's Type into the module under the alias t
(i.e., import Type from '@sinclair/typebox' aliased to t) so the schema builder
symbols t.Object/t.String/t.Number resolve; update the top of the file to
include this import and ensure any existing imports (like Elysia) remain intact.
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
CHANGELOG.mdexample/a.tsexample/newFile.ts
🧰 Additional context used
🪛 Biome (2.1.2)
example/a.ts
[error] 18-18: Expected an expression but instead found the end of the file.
Expected an expression here.
(parse)
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
| import { Elysia, t } from '../src' | ||
| import { z } from 'zod' | ||
| import { req } from '../test/utils' | ||
| import { Elysia } from '../src' |
There was a problem hiding this comment.
Missing import for t (TypeBox schema builder).
The code uses t.Object(), t.String(), and t.Number() for body validation, but t is never imported. This will cause a ReferenceError at runtime.
Proposed fix
-import { Elysia } from '../src'
+import { Elysia, t } from '../src'📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| import { Elysia } from '../src' | |
| import { Elysia, t } from '../src' |
🤖 Prompt for AI Agents
In `@example/a.ts` at line 1, The file uses t.Object, t.String, and t.Number but
never imports t; add an import that brings TypeBox's Type into the module under
the alias t (i.e., import Type from '@sinclair/typebox' aliased to t) so the
schema builder symbols t.Object/t.String/t.Number resolve; update the top of the
file to include this import and ensure any existing imports (like Elysia) remain
intact.
| new Elysia() | ||
| .post( | ||
| "/create-post", | ||
| async (ctx) => { | ||
| return { | ||
| message: "Post Created", | ||
| data: ctx.body, | ||
| }; | ||
| }, | ||
| { | ||
| body: t.Object({ | ||
| name: t.String(), | ||
| content: t.String(), | ||
| safeAge: t.Number(), | ||
| }), | ||
| }, |
There was a problem hiding this comment.
Truncated file — missing closing syntax and server startup.
The file ends abruptly at line 18 with a trailing comma, leaving the .post() call and Elysia chain incomplete. This causes the parse error flagged by static analysis.
Proposed fix
new Elysia()
-.post(
+ .post(
"/create-post",
async (ctx) => {
return {
message: "Post Created",
data: ctx.body,
};
},
{
body: t.Object({
name: t.String(),
content: t.String(),
safeAge: t.Number(),
}),
- },
+ }
+ )
+ .listen(3000)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| new Elysia() | |
| .post( | |
| "/create-post", | |
| async (ctx) => { | |
| return { | |
| message: "Post Created", | |
| data: ctx.body, | |
| }; | |
| }, | |
| { | |
| body: t.Object({ | |
| name: t.String(), | |
| content: t.String(), | |
| safeAge: t.Number(), | |
| }), | |
| }, | |
| new Elysia() | |
| .post( | |
| "/create-post", | |
| async (ctx) => { | |
| return { | |
| message: "Post Created", | |
| data: ctx.body, | |
| }; | |
| }, | |
| { | |
| body: t.Object({ | |
| name: t.String(), | |
| content: t.String(), | |
| safeAge: t.Number(), | |
| }), | |
| } | |
| ) | |
| .listen(3000) |
🧰 Tools
🪛 Biome (2.1.2)
[error] 18-18: Expected an expression but instead found the end of the file.
Expected an expression here.
(parse)
🤖 Prompt for AI Agents
In `@example/a.ts` around lines 3 - 18, The Elysia app chain and .post() call are
left unterminated causing a parse error; close the route options and callback by
adding the missing closing braces/parentheses and finish the Elysia chain (e.g.,
close the .post(...) call, then call .listen(...) or start the server) so the
file ends with a complete expression; specifically update the code around the
Elysia instance and the "/create-post" route (the new Elysia() instantiation and
its .post handler) to include the missing closing brace/parenthesis and a server
startup call such as .listen(3000) or equivalent, then add the terminating
semicolon.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/adapter/bun/handler.ts`:
- Around line 502-503: There's a typo in the TypeScript directive above the
conditional checking response?.toResponse: replace the incorrect
"@ts-expect-errors" with the correct "@ts-expect-error" so the compiler
recognizes the directive; update the comment immediately above the if (typeof
response?.toResponse === 'function') check to use the singular form.
♻️ Duplicate comments (1)
CHANGELOG.md (1)
1-1: Missing release date in version header.This issue was previously flagged. Consider adding the release date for consistency with other changelog entries (e.g.,
# 1.4.22 - 5 Jan 2026).
🧹 Nitpick comments (3)
CHANGELOG.md (1)
8-8: Inconsistent markdown link format.The first link uses the full URL as display text
[https://github.com/elysiajs/elysia/issues/1617](...)while other changelog entries use the shorthand format[#1617](...). Consider using the shorthand for consistency.-- [https://github.com/elysiajs/elysia/issues/1617](https://github.com/elysiajs/elysia/issues/1617), [`#1623`](https://github.com/elysiajs/elysia/pull/1623) AOT compilation removes beforeHandle when using arrow function expression +- [`#1617`](https://github.com/elysiajs/elysia/issues/1617), [`#1623`](https://github.com/elysiajs/elysia/pull/1623) AOT compilation removes beforeHandle when using arrow function expressionsrc/adapter/bun/handler.ts (1)
522-536: Consider aligning errorToResponse signature with web-standard handler.The web-standard version types the error parameter as
Error & { toResponse?(): MaybePromise<Response> }, which allows removing some@ts-expect-errorcomments. This handler still uses@ts-expect-erroron lines 523 and 525. For consistency and to further reduce suppressions, consider adding the same typed signature here.src/adapter/web-standard/handler.ts (1)
560-576: Good typing improvement, but inconsistent@ts-ignoreusage with bun handler.The typed
toResponse?(): MaybePromise<Response>signature is a nice improvement. However, line 575 still uses@ts-ignorefor theraw?.thencheck, while the equivalent code insrc/adapter/bun/handler.ts(line 535) has no suppression. Given the changelog goal to "reduce ts-ignore/ts-expect-error on promise map handler", consider removing this@ts-ignoreif the typed signature makes it unnecessary, or add consistent suppression to the bun handler if it's still needed.
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
CHANGELOG.mdsrc/adapter/bun/handler.tssrc/adapter/utils.tssrc/adapter/web-standard/handler.tssrc/compose.ts
💤 Files with no reviewable changes (1)
- src/compose.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/adapter/utils.ts
🧰 Additional context used
🧬 Code graph analysis (2)
src/adapter/bun/handler.ts (2)
src/adapter/utils.ts (1)
handleFile(8-61)src/universal/file.ts (1)
ElysiaFile(99-168)
src/adapter/web-standard/handler.ts (3)
src/adapter/bun/handler.ts (3)
mapResponse(22-156)mapCompactResponse(404-520)errorToResponse(522-550)src/index.ts (4)
mapResponse(2758-2769)error(3088-3128)MaybePromise(8267-8267)Context(8197-8197)src/types.ts (1)
MaybePromise(286-286)
🔇 Additional comments (5)
src/adapter/bun/handler.ts (2)
40-40: LGTM!Good simplification - inlining the handleFile call is cleaner.
122-123: LGTM!The explicit
Promise<unknown>type casting improves type safety over bareresponse?.thenchecks, aligning with the goal to reduce ts-ignore/ts-expect-error usage.src/adapter/web-standard/handler.ts (3)
16-16: LGTM!Good addition of
MaybePromiseimport to support the improved typing inerrorToResponse.
152-155: LGTM!Consistent Promise handling refactor using explicit type casting, improving type safety.
292-295: LGTM!Consistent Promise handling refactors across the default case branches, using explicit
Promise<unknown>type casting.Also applies to: 411-414, 535-538
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
| // @ts-expect-errors | ||
| if (typeof response?.toResponse === 'function') |
There was a problem hiding this comment.
Typo in TypeScript directive comment.
@ts-expect-errors should be @ts-expect-error (singular). The current typo means the directive won't be recognized by TypeScript.
🔧 Proposed fix
- // `@ts-expect-errors`
+ // `@ts-expect-error`📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // @ts-expect-errors | |
| if (typeof response?.toResponse === 'function') | |
| // `@ts-expect-error` | |
| if (typeof response?.toResponse === 'function') |
🤖 Prompt for AI Agents
In `@src/adapter/bun/handler.ts` around lines 502 - 503, There's a typo in the
TypeScript directive above the conditional checking response?.toResponse:
replace the incorrect "@ts-expect-errors" with the correct "@ts-expect-error" so
the compiler recognizes the directive; update the comment immediately above the
if (typeof response?.toResponse === 'function') check to use the singular form.
Summary by CodeRabbit
Bug Fixes
Tests
Chores / Documentation
Other
✏️ Tip: You can customize this high-level summary in your review settings.