fix: name the handler contract when a non-Response is returned in dev - #247
Conversation
🦋 Changeset detectedLatest commit: bbb344a The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 22 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?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 reviews. How do review 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 refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
WalkthroughThe runtime now registers 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Comment |
A handler returning data directly (the return-an-object habit) sailed through call() and reached the adapter, which failed reading headers off it -- the error named copyResponseHeaders in a dist file and never the route or the contract. A dev-mode guard now rejects it naming the verb, the route, the returned type, and what to return instead. Writing the guard exposed a second bug: the NotHandled/NotMatched sentinels were per-copy unique symbols, and a build can load more than one copy of the runtime module -- the not-handled fixture does. A sentinel returned from user code then failed the identity comparison in another copy and flowed onward as if it were a response, which the fixture only survived because its handler had already written to the platform response. The sentinels are now registered with Symbol.for, as kRender in the same module already is. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V888Mxok4otffCprmvyiKU
Same fix as on the netlify branch: the dx.md entry #243 landed uses both, so the full local lint fails on main. Identical content, so whichever branch merges first carries it and the other rebases clean. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V888Mxok4otffCprmvyiKU
The dev branch already exists, so the guard belongs inside it rather than re-testing NODE_ENV in the shared tail; it lets the sentinels pass since the shared check handles them after. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V888Mxok4otffCprmvyiKU
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V888Mxok4otffCprmvyiKU
1be4a91 to
bbb344a
Compare
Description
@marko/run: a dev handler that returns anything other than aResponse—return { items: [...] }, the auto-JSON habit from other frameworks — sailed throughcall(), whose terminal guard only rejectednulland theNotHandled/NotMatchedsentinels, and reached the node adapter as if it were aResponse. The adapter then iteratedresponse.headersonundefinedand the developer sawheaders is not iterablewith a stack topping out incopyResponseHeadersin a dist file — no route, no verb, no contract.A dev-only assertion in
call()now rejects any truthy non-Responsewith an error naming everything the old one didn't:Production builds skip the check, keeping the hot path unchanged (pinned by a test).
Writing the guard flushed out a second, pre-existing bug: the
NotHandled/NotMatchedsentinels were per-copy unique symbols, and a build can load more than one copy of the runtime module — thenot-handledfixture does. A sentinel returned from user code then failed the identity comparison in another copy and flowed onward into the adapter as if it were a response; the fixture only survived because its handler had already written to the platform response directly. The sentinels are now registered withSymbol.for, the same patternkRenderin the same module already uses.The branch also carries the same two-word cspell addition as #244 (a separate, droppable commit) since main's local
pnpm run lintcurrently fails without it.Motivation and Context
The misleading error steers whoever reads it — developer or coding agent — toward editing adapter internals instead of their handler. Typed projects are protected by
HandlerReturnValue, but plain-JS handlers are supported and get no compile-time signal.Coverage: a new
handler-returns-objectfixture reproduces the originalheaders is not iterablefailure on unmodified code and asserts the new message namesGET /api(dev-only; preview skipped since the guard is dev-gated), andcall-return-value.test.tscovers Response pass-through, fall-through on no return, the guard's message, production being unchecked, and cross-copy sentinel recognition. Both revert-checked in each direction.Screenshots (if appropriate):
Checklist:
Generated by Claude Code