Skip to content

Commit c9ede7b

Browse files
committed
fix(appkit): don't misdirect cache-unrelated typegen fatals to .appkit/
Make TypegenFatalError's cacheInitialized snapshot optional. A cache-unrelated fatal (e.g. a malformed definitions.json) now omits it and gets generic "Fix the FATAL error(s) above, then re-run generate-types" wording, instead of the bootstrap/drift message telling the operator to regenerate and commit .appkit/ (which only applies to failures tied to the type cache). Co-authored-by: Isaac Signed-off-by: Atila Fassina <atila@fassina.eu>
1 parent 2baef04 commit c9ede7b

2 files changed

Lines changed: 23 additions & 10 deletions

File tree

packages/appkit/src/type-generator/index.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,25 @@ export class TypegenFatalError extends Error {
178178
constructor(
179179
queries: QueryFatalError[],
180180
warehouseId?: string,
181-
cacheInitialized: boolean = true,
181+
cacheInitialized?: boolean,
182182
) {
183-
// Distinguish bootstrap (no committed cache yet) from drift (cache exists but is stale/missing key).
184-
// Bootstrap → operator needs to initialize; drift → operator needs to regenerate the affected key.
185-
const nextStep = cacheInitialized
186-
? // Drift: cache file exists but is missing/stale for the failing query/metric.
187-
warehouseId
188-
? `The committed ${pc.bold(".appkit/")} cache is missing or stale for the failed ${plural(queries.length, "query", "queries")}. Regenerate with ${pc.bold("generate-types --wait")} against warehouse ${pc.bold(warehouseId)} and commit ${pc.bold(".appkit/")}.`
189-
: `The committed ${pc.bold(".appkit/")} cache is missing or stale for the failed ${plural(queries.length, "query", "queries")}. Regenerate with ${pc.bold("generate-types --wait")} against a warehouse and commit ${pc.bold(".appkit/")}.`
190-
: // Bootstrap: no committed cache found; operator needs to initialize from scratch.
191-
`No committed type cache found (${pc.bold(".appkit/")}). Run ${pc.bold("generate-types --wait")} against a warehouse and commit ${pc.bold(".appkit/")} before building without warehouse access.`;
183+
// The cache snapshot is optional: callers whose failure relates to the type
184+
// cache pass it to get bootstrap/drift remediation; callers with an unrelated
185+
// fatal (e.g. a malformed definitions.json) omit it and get generic wording.
186+
const nextStep =
187+
cacheInitialized === undefined
188+
? // No cache snapshot: the failure is unrelated to the cache — don't
189+
// misdirect the operator toward regenerating/committing `.appkit/`.
190+
`Fix the ${pc.bold("FATAL")} error(s) above, then re-run ${pc.bold("generate-types")}.`
191+
: // Distinguish bootstrap (no committed cache yet) from drift (cache exists but is stale/missing key).
192+
// Bootstrap → operator needs to initialize; drift → operator needs to regenerate the affected key.
193+
cacheInitialized
194+
? // Drift: cache file exists but is missing/stale for the failing query/metric.
195+
warehouseId
196+
? `The committed ${pc.bold(".appkit/")} cache is missing or stale for the failed ${plural(queries.length, "query", "queries")}. Regenerate with ${pc.bold("generate-types --wait")} against warehouse ${pc.bold(warehouseId)} and commit ${pc.bold(".appkit/")}.`
197+
: `The committed ${pc.bold(".appkit/")} cache is missing or stale for the failed ${plural(queries.length, "query", "queries")}. Regenerate with ${pc.bold("generate-types --wait")} against a warehouse and commit ${pc.bold(".appkit/")}.`
198+
: // Bootstrap: no committed cache found; operator needs to initialize from scratch.
199+
`No committed type cache found (${pc.bold(".appkit/")}). Run ${pc.bold("generate-types --wait")} against a warehouse and commit ${pc.bold(".appkit/")} before building without warehouse access.`;
192200

193201
super(
194202
formatTypegenFailureMessage({

packages/appkit/src/type-generator/tests/index.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,11 @@ describe("generateFromEntryPoint — metric-view emission", () => {
727727

728728
expect(error).toBeInstanceOf(TypegenFatalError);
729729
expect((error as Error).message).toContain("definitions.json");
730+
// A config parse error is unrelated to the type cache: the remediation must
731+
// NOT tell the operator to regenerate/commit `.appkit/` (that's the cache
732+
// bootstrap/drift wording, reserved for callers that pass the cache snapshot).
733+
expect((error as Error).message).not.toContain(".appkit/");
734+
expect((error as Error).message).toContain("Fix the");
730735
// Query types were written before the metric config was read.
731736
expect(fs.existsSync(outFile)).toBe(true);
732737
});

0 commit comments

Comments
 (0)