Skip to content

Commit 88f730f

Browse files
fix(dbt-tools): lead a text error answer with the stale-manifest note
`--format text` printed only the error, fix and logs, so a `schema-verify` error that rested on an old manifest lost the note its JSON answer carries. The text lines now come from `failureLines()`, note first. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VEmKQx8gR7vd6ettA3mWjP
1 parent efa7dc9 commit 88f730f

3 files changed

Lines changed: 25 additions & 7 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/** What `--format text` prints on stderr for an error answer. */
2+
export function failureLines(failed: Record<string, unknown>): string[] {
3+
const lines: string[] = []
4+
// The note comes first, as in the JSON answer: the error rests on that manifest.
5+
const stale = failed.stale_manifest
6+
if (stale && typeof stale === "object" && "message" in stale) lines.push(String(stale.message))
7+
lines.push(String(failed.error))
8+
if ("fix" in failed) lines.push(String(failed.fix))
9+
if (Array.isArray(failed.logs)) lines.push(failed.logs.join("\n"))
10+
return lines
11+
}

‎packages/dbt-tools/src/index.ts‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { existsSync } from "fs"
33
import { read, type Config } from "./config"
44
import { init } from "./commands/init"
55
import { validate } from "./check"
6+
import { failureLines } from "./failure-text"
67

78
const USAGE = {
89
commands: {
@@ -64,18 +65,12 @@ function diagnose(err: Error): { error: string; fix?: string } {
6465
return { error: msg, fix: "Run: altimate-dbt doctor" }
6566
}
6667

67-
function printFailure(failed: Record<string, unknown>) {
68-
console.error(String(failed.error))
69-
if ("fix" in failed) console.error(String(failed.fix))
70-
if (Array.isArray(failed.logs)) console.error(failed.logs.join("\n"))
71-
}
72-
7368
function output(result: unknown) {
7469
const fmt = rest.includes("--format") && rest[rest.indexOf("--format") + 1] === "text"
7570
if (fmt && typeof result === "object" && result !== null) {
7671
const obj = result as Record<string, unknown>
7772
if ("error" in obj) {
78-
printFailure(obj)
73+
console.error(failureLines(obj).join("\n"))
7974
process.exit(1)
8075
}
8176
if ("sql" in obj) {

‎packages/dbt-tools/test/stale-manifest.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { ParsedManifest } from "@altimateai/dbt-integration"
44
import { create, hasModelLineage } from "../src/adapter"
55
import { children, parents } from "../src/commands/graph"
66
import { schemaVerify } from "../src/commands/schema-verify"
7+
import { failureLines } from "../src/failure-text"
78
import { recordManifest, staleManifestNote } from "../src/stale-manifest"
89

910
const WRITTEN_AT = Date.UTC(2026, 10, 5, 8, 0, 0)
@@ -88,6 +89,17 @@ describe("answers built from the manifest", () => {
8889
staleManifest()
8990
expect(Object.keys(await schemaVerify(notInManifest, ["--model", "a"]))).toEqual(["stale_manifest", "error"])
9091
})
92+
93+
test("a text error answer leads with the note too", async () => {
94+
staleManifest()
95+
const answer = await schemaVerify(notInManifest, ["--model", "a"])
96+
expect(failureLines(answer)).toEqual([staleManifestNote()!.message, String(answer.error)])
97+
})
98+
99+
test("a text error answer on a current manifest is the error alone", async () => {
100+
const answer = await schemaVerify(notInManifest, ["--model", "a"])
101+
expect(failureLines(answer)).toEqual([String(answer.error)])
102+
})
91103
})
92104

93105
describe("create", () => {

0 commit comments

Comments
 (0)