Repository navigation
Commit 37072bc
fix: bubble real dbt show error instead of generic "Could not parse" (#933)
* fix: bubble real dbt show error instead of generic "Could not parse"
`execDbtShow` swallowed `run()` rejections silently — when `dbt show`
crashed (e.g. corrupted `dbt_packages/*`, missing `dbt_project.yml`,
DB connection refused), callers saw a misleading "Could not parse
dbt show output in any format" message and treated it as transient.
The real `Runtime Error: ...` from `dbt`'s stderr never surfaced.
Capture the `execFile` rejection's `.stderr` and `.stdout`, scan
recovered JSON log lines for `level: "error"` events (dbt with
`--log-format json` emits structured error events even on crash),
and surface the real error. Preserve the existing generic message
only when both `run()` invocations exit 0 but the output is genuinely
unparseable — the condition the message was actually designed for.
- src/dbt-cli.ts: 2 catch blocks now retain the error; new
`extractDbtError()` helper picks structured event > stderr > message.
- test/dbt-cli.test.ts: 6 new cases (real stderr surfaces, structured
event preferred, ENOENT fallback, generic message preserved on
exit-0 unparseable). 24/24 pass.
Scoped to `execDbtShow`. `execDbtCompile` and `execDbtCompileInline`
share the same masking pattern but have manifest.json / `--quiet`
fallbacks that reduce impact — addressed separately if needed.
Closes #932
* test(dbt-tools): remove duplicate "Could not parse" test
The new test at dbt-cli.test.ts L199 ("preserves generic 'Could not
parse' when dbt exited 0 but output unparseable") used the same mock
implementation and asserted the same rejection string as the existing
"Tier 3: throws with helpful message when all tiers fail" test at
L145. The generic-error path is fully covered by Tier 3; any future
change to that behaviour would have had to be kept in sync across
two identical tests.
Addresses cubic-dev-ai review feedback on #933 (P3).
Tests: 23 pass / 0 fail in packages/dbt-tools/test/dbt-cli.test.ts.
Refs #932
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
* fix(dbt-tools): bubble real dbt show error correctly + redact SQL on failure
Final fix-up addressing reviewer feedback on this PR.
Production fixes (packages/dbt-tools/src/dbt-cli.ts):
- run(): capture stdout/stderr on execFile rejection. Node delivers them as
separate callback args, not as properties on the error; the previous bare
reject(err) discarded them so the catch-block's e.stdout / e.stderr were
always undefined and the "bubble real dbt error" path was inert in
production.
- execDbtShow: split the error throw by failure mode. Distinguish "primary
dbt show crashed" (surface the real dbt error) from "primary succeeded
but unparseable AND plain-text retry failed" (parser-regression message).
Throwing "dbt show failed: <plain-mode error>" when primary succeeded
would misattribute a parser regression as a dbt execution failure.
- execDbtShow: do not feed crashed-run stdout into Tier 1/2 heuristics.
Crash logs can contain incidental arrays that the heuristic scan would
happily return as "rows" (silent wrong data). Tier 1/2 are now gated
behind !primaryRunError; the crashed stdout is only consulted by
extractDbtError for structured level:"error" events.
- extractDbtError: pick the LAST level:"error" event (dbt emits a generic
header before the actionable message), strip ANSI from surfaced text,
and redact inline SQL from err.message via a new fallbackExitMessage
helper covering exit-code rejections AND signal/timeout kills. Spawn-
time failures (ENOENT etc.) keep their original message since it does
not embed the command line.
- execDbtShow: suppress the "dbt show failed:" prefix when the underlying
error already starts with a dbt category prefix (Compilation/Database/
Runtime/Parsing/Validation/Dependency Error). Avoids "dbt show failed:
Database Error: ..." doubling.
Test fixes (packages/dbt-tools/test/dbt-cli.test.ts):
- Mocks now pass stdout/stderr only via callback args, matching Node's
actual behaviour. Previous mocks pre-attached err.stdout / err.stderr,
which made the inert production code path appear to work — a false-
positive class the new mocks specifically guard against.
- New tests cover: parser-vs-dbt-failure attribution, last-event
preference, ANSI strip, SQL-redaction canaries (numeric exit code +
signal kill), category-prefix dedup, Buffer-typed stdout/stderr,
Tier 3 recovery, anti-spurious-rows on crash.
- Cleanup: TS type-clean catch pattern, drop redundant negative
assertions and a vacuous ^Error: regex.
33 pass / 0 fail.
Out of scope, tracked as follow-up issues:
- #943 — execDbtCompile / execDbtCompileInline mask real dbt errors
- #944 — execDbtShow returns malformed result on non-array data.preview
- #945 — execDbtCompileInline embeds full inline SQL in error message
Refs #932
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
* fix(dbt-tools): bubble real errors and redact SQL across all execDbt* paths
Pulls #943, #944, and #945 into this PR — each was tagged as out-of-scope
in the earlier rounds but they share so much of the same fix surface
(extractDbtError / fallbackExitMessage already in place) that fixing them
in-PR is cleaner than spawning three follow-up PRs.
Closes #943 — execDbtCompile / execDbtCompileInline used to swallow the
real dbt error with `try { … } catch { lines = [] }`. They now capture
the run error, skip the success-only tiers when the primary run failed
(same anti-spurious-data reasoning as execDbtShow), and throw via a new
shared `bubbleDbtError(label, primary, plain)` helper that combines
extractDbtError + fallbackExitMessage with the same SQL-safety,
ANSI-stripping, and category-prefix-dedup guarantees.
Closes #944 — execDbtShow Tier 1 used to assign a truthy non-array
`data.preview` straight into `rows`, returning `{ data: {} }` to callers
and crashing downstream `.map` / `.length`. The else-branch now guards
with `Array.isArray(preview)` and emits empty rows for any unexpected
shape (object, number, etc.).
Closes #945 — execDbtCompileInline's final throw used `e.message`
directly, which is Node's "Command failed: <dbt-path> compile --inline
'<entire user SQL>' …" — leaking PII / secrets templated into the inline
query. The new bubbleDbtError helper routes through fallbackExitMessage,
which redacts the command line for both exit-code and signal/timeout
rejections.
Tests: 41 pass / 0 fail (was 33). New coverage:
- execDbtShow non-array preview shape (object + numeric)
- execDbtCompile error bubbling (real stderr, structured JSON event,
category-prefix dedup)
- execDbtCompileInline error bubbling
- execDbtCompileInline SQL-redaction canaries for both exit-code and
signal-kill failure modes
Refs #932
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
---------
Co-authored-by: Haider <[email protected]>
Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>1 parent 07eaa94 commit 37072bc
2 files changed
Lines changed: 680 additions & 86 deletions
0 commit comments