From d12b24f6c2f6171ec9f5b5c33070366ebbe5e56d Mon Sep 17 00:00:00 2001 From: Mark Probst Date: Mon, 20 Jul 2026 16:36:26 -0400 Subject: [PATCH] fix(schema-input): report clean fetch error for missing schema paths (#2812) When --src-lang schema was given a nonexistent source path (e.g. a literal wildcard like '*.json' that a shell such as PowerShell doesn't expand), JSONSchemaStore.get swallowed the fetch error and returned undefined, and Resolver.resolveVirtualRef then tried to read virtualRef.address on a Ref with no address, panicking with "Internal error: Defined value expected, but got undefined." instead of a real diagnostic. Use virtualRef.toString() (which doesn't require an address) when building the fetch-error message, so a missing schema path now reports a normal "Could not fetch schema ..." error instead of crashing. Co-Authored-By: gpt-5.6-sol via pi --- .../src/input/JSONSchemaInput.ts | 2 +- test/unit/missing-schema-path.test.ts | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 test/unit/missing-schema-path.test.ts diff --git a/packages/quicktype-core/src/input/JSONSchemaInput.ts b/packages/quicktype-core/src/input/JSONSchemaInput.ts index d3a0e4feef..70a51256ee 100644 --- a/packages/quicktype-core/src/input/JSONSchemaInput.ts +++ b/packages/quicktype-core/src/input/JSONSchemaInput.ts @@ -783,7 +783,7 @@ class Resolver { return [schema, result[1]]; } - return schemaFetchError(base, virtualRef.address); + return schemaFetchError(base, virtualRef.toString()); } public async resolveTopLevelRef(ref: Ref): Promise<[JSONSchema, Location]> { diff --git a/test/unit/missing-schema-path.test.ts b/test/unit/missing-schema-path.test.ts new file mode 100644 index 0000000000..8656b820dd --- /dev/null +++ b/test/unit/missing-schema-path.test.ts @@ -0,0 +1,36 @@ +import * as fs from "node:fs"; +import * as os from "node:os"; +import * as path from "node:path"; + +import { + FetchingJSONSchemaStore, + InputData, + JSONSchemaInput, + quicktype, +} from "quicktype-core"; +import { expect, test } from "vitest"; + +// Regression test for issue #2812: shells such as PowerShell pass wildcard +// arguments through literally, so a schema wildcard with no matching file must +// report a normal missing-file error rather than an internal error. +test("missing JSON Schema paths report the fetch error", async () => { + const tempDir = fs.mkdtempSync( + path.join(os.tmpdir(), "quicktype-missing-schema-"), + ); + const missingPath = path.join(tempDir, "*.json"); + + try { + const schemaInput = new JSONSchemaInput(new FetchingJSONSchemaStore()); + await schemaInput.addSource({ name: "TopLevel", uris: [missingPath] }); + const inputData = new InputData(); + inputData.addInput(schemaInput); + + await expect( + quicktype({ inputData, lang: "typescript" }), + ).rejects.toThrow( + `Could not fetch schema #, referred to from ${missingPath}#`, + ); + } finally { + fs.rmSync(tempDir, { recursive: true, force: true }); + } +});