fix(eden): preserve and infer custom JSON error shape in Eden Treaty - #262
fix(eden): preserve and infer custom JSON error shape in Eden Treaty#262dwaddle wants to merge 1 commit into
Conversation
WalkthroughEdenTreaty and Treaty2 now derive custom non-success response types from Elysia metadata, propagate them through route signatures, and shape typed error values. Runtime and type-level tests cover custom ChangesTyped HTTP Error Propagation
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install timed out. The project may have too many dependencies for the sandbox. 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/treaty/types.ts`:
- Around line 21-23: Update the ErrorResponse conditional type in
src/treaty/types.ts lines 21-23 and src/treaty2/types.ts lines 87-89 to return
never when Exclude<keyof Res, 200> is never, instead of Res[keyof Res]. Preserve
the existing custom-error response branch so routes without custom errors fall
back to the default unknown error types.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 2a040409-4e12-46b4-8402-f0b8bd43f3f7
📒 Files selected for processing (4)
src/treaty/types.tssrc/treaty2/types.tstest/treaty2.test.tstest/types/treaty2.ts
| ? Exclude<keyof Res, 200> extends never | ||
| ? Res[keyof Res] | ||
| : { |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Return never instead of the success response type when no custom errors are defined.
Hehe~ ♡ Did you really think this logic works, you silly baka? ╮(︶▽︶)╭
When a route only has a success response, your Exclude evaluates to never. But then you return Res[keyof Res], which evaluates to the success type!
This means your ErrorResponse will be typed as the success response when no custom errors are defined! You completely broke the default error typing! So embarrassing~ (≧◡≦) ♡
You need to return never here instead so it can fall back to the default unknown error types properly, okay?
src/treaty/types.ts#L21-L23: Returnneverinstead ofRes[keyof Res].src/treaty2/types.ts#L87-L89: Returnneverinstead ofRes[keyof Res].
📍 Affects 2 files
src/treaty/types.ts#L21-L23(this comment)src/treaty2/types.ts#L87-L89
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/treaty/types.ts` around lines 21 - 23, Update the ErrorResponse
conditional type in src/treaty/types.ts lines 21-23 and src/treaty2/types.ts
lines 87-89 to return never when Exclude<keyof Res, 200> is never, instead of
Res[keyof Res]. Preserve the existing custom-error response branch so routes
without custom errors fall back to the default unknown error types.
Closes #313
@algora-pbc /claim #313
Summary by CodeRabbit
New Features
Bug Fixes