Repository navigation
fix(errors): register the codes constructive-db main raises, including ones handed to raise helpers - #2017
Conversation
…g ones handed to raise helpers
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
Review complete. 🟡 2 medium 💬 Inline comments (2)
🧹 Nitpicks (1) — 🟢 1 low
The change widens the database-error registry with newly audited SQL error codes and aligns tests with the regenerated inventory. A Python audit script scans SQL sources for raise sites, an inventory JSON captures the resulting codes, and
The audit script has parser-robustness issues that can silently skew the generated inventory, so counts should be re-verified after fixing. Reviewed commit: 7198419 |
There was a problem hiding this comment.
This PR expands the DB-error taxonomy: it re-audits SQL raise sites with audit-db-errors.py, regenerates db-error-inventory.json, adds new codes to the TS registry, and updates the format-error and storage-refusal tests.
Key findings
- 🟡
scan_indirectruns on unstripped text, comments mint codes — audit-db-errors.py:220 - 🟡 Corpus-wide param map conflates same-named variables — audit-db-errors.py:117
| for rex in (NAMED_ARG_RE, PARAM_DEFAULT_RE): | ||
| for m in rex.finditer(text): | ||
| if m.group(1) in params: | ||
| yield m.group(2), params[m.group(1)] |
There was a problem hiding this comment.
🟡 bug · medium
scan_indirect runs on unstripped text, comments mint codes
Comments are stripped only inside scan_raise_params (packages/errors/scripts/audit-db-errors.py:186), but scan_indirect matches NAMED_ARG_RE/PARAM_DEFAULT_RE against the raw file text passed from scan (packages/errors/scripts/audit-db-errors.py:266). An assignment that exists only inside an SQL comment — e.g. a documented example like -- v_status := 'SOME_CODE' — whose variable name was ever seen as a raise parameter yields a phantom inventory entry that generate-registry.py promotes to a registry code with an HTTP status, and registry-sync.test.ts then blocks its removal without a full re-audit. The same asymmetry counts real assignments in commented-out code.
📋 Prompt for AI Agents
In packages/errors/scripts/audit-db-errors.py, hoist SQL_COMMENT_RE.sub('', text) out of scan_raise_params (line 186) into a helper applied to each file's text once in read_all (lines 248-255), so both scan_raise_params and scan_indirect (lines 220-223) see identical comment-free text; otherwise a commented-out param := 'CODE' silently adds a phantom error code to db-error-inventory.json and the generated registry.
| PARAM_RAISE_RE = re.compile(rf"raise_(?:error|exception)\s*\(\s*({IDENT})\s*[,)]") | ||
| # raise_error(<param> || '_SUFFIX', ...): the code is a parameter plus a suffix. | ||
| PREFIX_RAISE_RE = re.compile(rf"raise_error\s*\(\s*({IDENT})\s*\|\|\s*'([A-Z0-9_]+)'") | ||
| NAMED_ARG_RE = re.compile(rf"\b({IDENT})\s*:=\s*'([A-Z][A-Z0-9_]{{2,}})'") | ||
| PARAM_DEFAULT_RE = re.compile(rf"\b({IDENT})\s+text\s+DEFAULT\s+'([A-Z][A-Z0-9_]{{2,}})'") | ||
| # A code carried in a jsonb payload that a generator later raises verbatim. | ||
| JSON_CODE_RE = re.compile(r"'error_code'\s*,\s*'([A-Z][A-Z0-9_]{2,})'") |
There was a problem hiding this comment.
🟡 bug · medium
Corpus-wide param map conflates same-named variables
scan_raise_params builds a single global {param: class} map across the whole constructive-db corpus (packages/errors/scripts/audit-db-errors.py:182-195), and scan_indirect then yields a code for any name := 'ALL_CAPS' in any file whose left side collides with a registered name (packages/errors/scripts/audit-db-errors.py:220-223). Because PARAM_RAISE_RE also treats a raise's first positional argument as code-bearing even when it is a message variable, two unrelated PL/pgSQL variables sharing a generic name (v_status, v_code) cross-contaminate: an ordinary string assignment in one module becomes a phantom error code with the other module's class, and both the inventory counts and the class (which drives HTTP status in generate-registry.py) can be wrong.
📋 Prompt for AI Agents
In packages/errors/scripts/audit-db-errors.py, tighten the indirect pipeline: (a) PARAM_RAISE_RE (line 117) should only register a parameter when the raise's first argument plausibly carries a code (e.g. name ends in _code/_err); (b) track raise parameters per file or per function body instead of the single global params dict (lines 182-195), and only yield codes from scan_indirect (lines 220-223) for assignments within the registering scope. This prevents unrelated same-named variables from minting phantom codes in db-error-inventory.json.
Summary
Refreshes the
@constructive-io/errorsregistry from constructive-db main (a8d61439e3c): 844 → 912 codes (69 added, 1 removed), regenerated with the documented procedure (audit-db-errors.pythengenerate-registry.py; no generated file hand-edited).What happens today for an unregistered database code
Pinned by three new tests in
graphql/server/src/middleware/__tests__/format-error.test.ts. It is not masked:class: 'public'extensions.{code, class: 'public', context}passed through unchangedclass: 'internal'extensions.errorId, and it is loggedinternalby the registry fallback, same as aboveparse()trustsDETAIL.classbefore the registry, so the registry gap does not change masking. What an unregistered code loses is its HTTP status (httpStatusFor→500, reported once) and its message copy (toError/formatfall back to the humanized code).formatErroritself attaches no HTTP status. The README said unregistered codes were "masked"; corrected.The audit missed codes handed to a raise helper
FILE_STATUS_INVALIDnever appears asraise_error('FILE_STATUS_INVALID', …); the generator passeswrong_status_code := 'FILE_STATUS_INVALID'to a helper that doesraise_error(wrong_status_code, ctx, 'internal'). The audit only read literal first arguments. It now finds the parameters that reach a raise and collects the codes passed to them:A class spelled at a literal raise still wins; the helper's class only fills in when there is none. This added 11 codes the plain refresh would have missed (
FILE_STATUS_INVALID,RESOURCE_CPU_CAP_EXCEEDED,RESOURCE_MEMORY_CAP_EXCEEDED,EXECUTION_DEADLINE_EXCEEDS_RETENTION,DEADLINE_EXCEEDS_RETENTION,SITE_CONTENT_SCOPE_MISMATCH,REQUIRED_CAPABILITIES_NOT_HELD, fourPROCESS_*_INSERT_ON_FILES_TABLE) and gaveRESOURCE_STORAGE_TOTAL_CAP_EXCEEDEDits real class (internal/500 →public/400).The three codes from the task
SECRET_NOT_FOUND:public, 404.FILE_STATUS_INVALID:internal, 500 — the db raises it'internal'from the storage writers, so it follows the generator's rule for internal codes rather than a hand-picked 409.FILE_NOT_FOUND: collision resolved without a rename. The curated entry keeps its typed{ filePath, type }shape, classinternaland 404 (unchanged forpgpmcallers, and it already overrides the generated entry). Its message no longer assumesfilePath, so the db's{ file_id }shape rendersFile not found.instead ofFile not found: undefined.Review notes
STORAGE_GC_CONTENT_HASH_UNSUPPORTEDis dropped: db main no longer raises it.generatedOnlyflips tofalsefor ~20 codes whose source the audit can now see.'<CODE>: message'throughauthz_column_securitycarry no class, so they stay on the name heuristic (REQUIRED_CAPABILITIES_NOT_HELD→internal/500, like the existingAPI_PRIVILEGED_*_FORBIDDEN).Link to Devin session: https://app.devin.ai/sessions/9acb04639d9b47caa0094faf9fb1e9c6
Open in Devin Desktop: https://app.devin.ai/desktop/session/9acb04639d9b47caa0094faf9fb1e9c6?variant=devin
Requested by: @pyramation
🟢 Devin Review found nothing to fix · View findings