Skip to content

fix(errors): register the codes constructive-db main raises, including ones handed to raise helpers - #2017

Merged
devin-ai-integration[bot] merged 1 commit into
mainfrom
feat/errors-registry-refresh
Nov 17, 2026
Merged

devin-ai-integration[bot] merged 1 commit into
mainfrom
feat/errors-registry-refresh

Conversation

@pyramation

@pyramation pyramation commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Refreshes the @constructive-io/errors registry from constructive-db main (a8d61439e3c): 844 → 912 codes (69 added, 1 removed), regenerated with the documented procedure (audit-db-errors.py then generate-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:

How the db raised it GraphQL response
class: 'public' message = the code, extensions.{code, class: 'public', context} passed through unchanged
class: 'internal' same, plus extensions.errorId, and it is logged
no class classified internal by the registry fallback, same as above

parse() trusts DETAIL.class before 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/format fall back to the humanized code). formatError itself attaches no HTTP status. The README said unregistered codes were "masked"; corrected.

The audit missed codes handed to a raise helper

FILE_STATUS_INVALID never appears as raise_error('FILE_STATUS_INVALID', …); the generator passes wrong_status_code := 'FILE_STATUS_INVALID' to a helper that does raise_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:

raise_error(<param>, …, 'class')            -> param carries a code, with that class
<param> := 'CODE' / <param> text DEFAULT 'CODE'
'error_code', 'CODE'                         (jsonb payload raised by a generator)
raise_error(<param> || '_SUFFIX', …)        -> resolved against positional args of calls to the declaring function

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, four PROCESS_*_INSERT_ON_FILES_TABLE) and gave RESOURCE_STORAGE_TOTAL_CAP_EXCEEDED its 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, class internal and 404 (unchanged for pgpm callers, and it already overrides the generated entry). Its message no longer assumes filePath, so the db's { file_id } shape renders File not found. instead of File not found: undefined.

Review notes

  • STORAGE_GC_CONTENT_HASH_UNSUPPORTED is dropped: db main no longer raises it.
  • generatedOnly flips to false for ~20 codes whose source the audit can now see.
  • Codes raised as '<CODE>: message' through authz_column_security carry no class, so they stay on the name heuristic (REQUIRED_CAPABILITIES_NOT_HELD → internal/500, like the existing API_PRIVILEGED_*_FORBIDDEN).
  • A code assembled at runtime in any other way is still invisible to the audit.

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

Devin Review

@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@luxor-code-review

luxor-code-review Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Review complete. 🟡 2 medium

💬 Inline comments (2)

🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 FILE_NOT_FOUND type excludes the file_id producer (registry.ts:694) — The FILE_NOT_FOUND context type defineError<{ filePath: string; type?: string }> marks filePath as required, but the same code is now raised by storage writers with only { file_id } and no path, per the new comment and test (packages/errors/src/registry.ts:694).

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 registry.ts maps them to GraphQL-safe errors while tests in the server middleware and the errors package lock in the new expectations.

Files Change
packages/errors/scripts/audit-db-errors.py Adds/extends the Python scanner that extracts raise codes from SQL sources
packages/errors/scripts/db-error-inventory.json Regenerated audit output enumerating DB error codes
packages/errors/src/registry.ts Registry updated with new codes and class/HTTP mappings
packages/errors/__tests__/storage-refusals.test.ts, packages/errors/README.md Tests and docs updated to match the expanded taxonomy
graphql/server/src/middleware/__tests__/format-error.test.ts Format-error middleware tests updated for the new registry behavior

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

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@luxor-code-review luxor-code-review Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines +220 to +223
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)]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Comment on lines +117 to +123
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,})'")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

@devin-ai-integration
devin-ai-integration Bot merged commit d92dd40 into main Nov 17, 2026
21 checks passed
@devin-ai-integration
devin-ai-integration Bot deleted the feat/errors-registry-refresh branch November 17, 2026 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant