Ways out the checker didn't see: a call that throws past a release, std's q under another name, an error q passes on that the function doesn't declare #140
Loading…
Reference in a new issue
No description provided.
Delete branch "ways-out"
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?
Three programs that pass
tscstrict,safe-ts check --idiomatic --deny-warningsand oxlint, and are wrong when they run. All three came out of an outside audit ofmain; I confirmed each on the binary before anything was built.The first leaves a resource open on a path the rules took to be impossible. The second is one rule reading a name's text. The third is a type that lies:
qgives TypeScript the value, sotscnever compares the two error types, and a caller's exhaustivematchmeets an error it has no arm for. Before this, onlysafe-ts emitfollowed bytscfound it, which is not in the loop an agent runs.What changes
A call that throws is a way out for
unreleased-resourceandunbalanced-update. A call between the acquisition and the release (or between a change and its undo) counts when the whole-program pass knows it can throw where it stands: a function of the project that throws or propagates, aThrows/Throwingslot, a built-in or a library member the maps mark as throwing, or a built-in that runs a throwing callback right away (list.forEach(check)). The file lists the calls and the pass decides, the same split the rules already use forawaits. A call that cannot fail is not a way out, and neither is one the checker cannot resolve: taking those to throw too changes no finding anywhere measured.std's names are std's however they are imported. The shared normalisation now reads
import { q as ask }(andMut as Lent,isErr as failed, a pack's safe version under another name) by the exported name, so every rule knows it; messages and fixes keep the name the file writes.R.q(...)through a namespace import is read the same way, also next to a renamed import.New rule
q-undeclared-error(error). It compares the errorq(...)passes on with the error the enclosing function declares, wherever both can be read from what is written: a project function's declared return type (across files, methods,q(await f()), aconstread once), std's helpers (unsafegivesunknown,parseJsonaJsonError; a table a test checks against std's sources), a pack's safe version, a declared function type, a function with no declared return type, and what a mapper returns. Literals, primitives,Enums and classes are compared by identity; anything it cannot decide is silent, and the page says exactly what is compared.Evidence
forEach,map,reduce,some,sort; a throw inside an argument or a template). 13 fine forms, all silent (a call that cannot fail, a release infinally, a callee that catches its own throw, a callback that runs later).unknownandstringdeclared, a mapper that fits, a type parameter).R.q(...)asR(...). All fixed in the second round.q-undeclared-error, all real: functions declaringResult<..., string>that pass on theErrorobject of a safe file-system call. Nothing else changes. Of its 300q(...)sites the rule compares both sides at 238; the page lists the other 62 by kind.sync-throw-skips-release,sync-throw-skips-undo,q-passes-undeclared-error). 16 of 103 escape.What turns red on upgrade
q-undeclared-erroris an error. Declare the error in the return type, or turn it into a declared one withq(result, (error): Declared => ...).unreleased-resourceandunbalanced-update(warnings) may report a path they did not see before. None on the code measured. The fix istry/finally.What stays unseen
aliased-mutmodels no way out by exception at all. Listed in the flow guide; a change to the loan analysis of its own.R.q(...)in a file that also declares a nameqof its own (as before this change).Found and left
safe-ts emitwrites an import line that does not parse whenqis used through a namespace import (import * as R from "…/result";, Err as __qErr).maindoes the same; it gets its own fix with transform tests.Created with Claude Opus 5.5 (implementation) and Claude Fable 5.2 (review and acceptance tests) in Claude Code.
What was open (review of 7b2d3f74's parent): with `import { q as ask }` and `import * as R` of the same module in one file, `renamed_imports` made the first `q`, so the namespace member `R.q` was no longer read as a name (a binding called `q` existed) and the leak past `R.q(parse(n))` went silent, where the starting commit reported it. Findings also quoted the call as `R(...)`. What closes it: a namespace member of a SAFE-TS module that the file also imports by that name is read as that binding (no import added), and a copy of it (`const take = R.q`) names that binding too; messages quote the callee as written, dots included. The harness rewrites one site at a time and can't write the two imports together: fixtures for it in `unreleased_resource` and `q_undeclared_error`. Two by-design lines for `R?.q(...)` and `const RCopy1 = R; RCopy1.q(...)`, which the transform doesn't rewrite (checked with `safe-ts emit`); `miss no-mutable-global callee-const` closes as a side effect. Co-Authored-By: Claude Opus 5.5 <[email protected]>