chore(auth): remove dead try/catch around isMaster + getCompanyId in attachAuth#162
Merged
Merged
Conversation
…attachAuth
`isMaster` and `getCompanyId` both wrap their DB query in a
try/catch INTERNALLY (see auth.js:97-109 and 111-125): on any
Sequelize / pg error they `log.error` and return `false` or `-1`
respectively. The errors don't propagate.
So the outer `try { req.isMaster = await isMaster(authKey) }
catch { return res.status(500) }` in attachAuth had nothing to
catch — the awaited promise never rejects. Same for the
getCompanyId wrapper below it. Both `500` paths were unreachable
dead code that misled readers into thinking attachAuth
distinguished "auth failed" from "DB down".
Strip the dead try/catch. Add a comment explaining the
swallow-into-sentinel design so the next reader doesn't
re-introduce the outer catches, and call out the real fix path
if anyone DOES want DB-down to surface as 500 (push the throw
back up from isMaster / getCompanyId, then layer a catch here
that's actually reachable). Behaviour unchanged; test suite
unchanged at 614 passing.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
CryptoJones
added a commit
that referenced
this pull request
May 19, 2026
Cleanup follow-up to #162, which removed the outer try/catch in attachAuth. Since attachAuth no longer has any 500-emitting path (its internal callees swallow infrastructure errors into sentinels and always invoke next()), the `attachOk` boolean was guaranteed true after the awaited Promise resolved. The dead `if (!attachOk) return;` line and its stale "attachAuth already sent a 500" comment misled readers into thinking resolveAuth still had a divergent error path. Drop both. Behavior unchanged. All 688 tests still pass. Co-authored-by: Aaron K. Clark <akclark@thenetwerk.net> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #161.
Summary
The outer
try { req.isMaster = await isMaster(authKey) } catch { res.status(500) }(and the equivalent wrapper aroundgetCompanyId) inattachAuthwas dead code: both inner helpers wrap their Sequelize query in try/catch and returnfalse/-1sentinels on error rather than throwing. The outer catch had nothing to handle.Misleading: readers think
attachAuthdistinguishes "DB down" (500) from "auth fails" (downstream 403). It does not — a DB outage surfaces as 403 "Invalid Authorization Key.", with the actual cause only in operator-side logs.Strip the dead wrappers. Add a comment explaining the swallow-into-sentinel design + the real-fix path if anyone wants DB-down to surface as 500 (push the throw back up from
isMaster/getCompanyId; cascading refactor, separate PR).Test plan
npm run lint— clean (eslint'sargs: "after-used"default letsresslide sincenextafter it is used)npm test— 614 passed, 15 skipped (unchanged from master; no behaviour shift)Proudly Made in Nebraska. Go Big Red! 🌽 https://xkcd.com/2347/