uncaught-propagation: functions handed to the runtime as entry points #21
Loading…
Reference in a new issue
No description provided.
Delete branch "rules/entry-point-handlers"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
This extends
uncaught-propagationrather than adding a rule. The existing design already has the right concept: callbacks that are "detached" from the code that registers them. It was missing two shapes.What it already covered (checked before changing anything): every function written in place as an argument to a call that isn't an array method,
unsafe,matchor an IIFE. That includessetTimeout(() => ...),server.on("request", async (req) => ...),http.createServer((req, res) => ...)andaddEventListener("message", (e) => ...).What it missed:
setTimeout(tick),queueMicrotask(flush),process.nextTick(f),http.createServer(handle),server.on("request", handle),parentPort.on("message", onMessage),addEventListener("message", onMessage)andglobalThis.setTimeout(f).handlewas recorded as propagating, but since nobody calls it, nothing was reported.worker.onmessage = onMessageandsocket.onclose = () => { ... }. An arrow assigned to anon*property was "untracked", so it was neither propagated nor reported.How:
CallSitegets areference: bool. analyze.rs records one when a named function is passed to a known entry point. Since the rebase it is resolved the way main's call-following (#5) resolves calls: a function declared in the file or imported, a nested helper (also a localconst onTick = () => ...), or a member (store.handlethrough a namespace import, an object literal'sapi.handle, a staticJobs.handle,this.handle). The entry points are timers (setTimeout,setInterval,setImmediate,queueMicrotask,requestAnimationFrame,requestIdleCallback, also onglobalThis/window/self),process.nextTick, listeners (.on,.once,.addListener,.prependListener,.prependOnceListener,.addEventListener, and the globaladdEventListener), andcreateServer/createSecureServer. A reference is also recorded when such a function is assigned to an all-lowercaseon*property (onmessage, notonChange, notonce). Inline functions assigned to such properties are now detached callbacks.uncaught-propagation, with its own message ("handed to the runtime to call later") and the failure path. A reference is not counted as a call of its owner: it is kept out offn_failureand propagation. It is also not judged bymust-use-result, the cross-fileunhandled-failure, orfloating-rejection(an async handler is reported once, asuncaught-propagation).tryinside the named function, and the page says so.Kept narrow on purpose: only those named entry points are recognized.
app.get("/", handle)and other framework routes are not judged, since Express, Fastify and similar frameworks catch what their handlers throw. A listener on the program's ownEventEmitteris treated like other listeners, even thoughemit()is synchronous; that matches what the rule already did for inline listeners, and the page says so.Docs: the
uncaught-propagationpage gets an entry-point section with a checked bad/good pair (acreateServer(handle)server), a quick-fix note and an updated "can't see". There is one sentence in the async guide and the README row is updated. No new registrations: same rule name, same plugin entry.Tests
fixtures/entry_points/(two files, cross-file import). It has 11 reported cases: timers, nextTick,createServer,.on/.once, globaladdEventListener,globalThis.setTimeout,onmessage = f, an inline function assigned toonmessage, and atryaround the registration (still reported). Accepted cases: a non-propagating function, a handler that catches inside, a camelCasehooks.onChange = f.mainat1fe2d1d(head5f39d94). Thatmainincludes #5 (call-following) and #11 (rejections vs throws, narrowing catches), both of which rewrote the code this PR touches. What changed:CallSitekeeps main'srejects/triesand this PR'sreference. A reference site has notrythat applies, andguarded,awaitedandpromise_handledare all false, so main's per-kindis_caughtnever counts it as caught.uncaught-propagationbefore main's floating/thrown split, so an async handler is still reported once and not asfloating-rejection.fn_failure(now a loop over all failure sources) skips references. Main's propagation pass already skipsdetachedsites, and references are marked detached.unhandled-failurecheck no longer has!call.guardedon main (it usesthrow_caught/rejection_caught); it keeps!call.reference.record_referencebuilds the callee with main'scall_targetand resolves local helpers through main'ssymbol_calls, instead of a bare name. This is the behaviour change in the "How" section above. The fixture has four new reported cases: a nested helper,handlers.routethrough a namespace import, an object literal method and a static method.uncaught-propagationpage is kept ahead of the entry-point section. The two "can't see" paragraphs are merged, and the old "class methods and nested helpers are not followed" (no longer true on main) is dropped.cargo nextest run --workspace: 104 passed, 0 failed.npm run test:std: 130 passed, 0 failed.npm run test:vite,npm run typecheck,npm run test:docs: passed.safe-ts checkonexamples/demo(22 problems, the demo's intended ones, none of them "handed to the runtime") andexamples/vue(none).setTimeout(onTick)with a local arrow andsetTimeout(this.tick)inside a class are both reported now.Left out / uncertain
setTimeout(this.tick)is reported for whattickpropagates; thatthisis unbound there is a separate problem the rule doesn't mention.export default { fetch(request) { ... } }(Bun, Deno, Workers) and other object-method entry points are not covered. Like class methods, they stay untracked.new Promise(executor),.then(fn)by name, andworker_threadsnew Worker(...)are unchanged.🤖 Generated with Claude Code
235d7f4135to5f39d943a7