Skip to content

fix(schema-input): report clean fetch error for missing schema paths#2967

Merged
schani merged 1 commit into
masterfrom
agent/fix-issue-2812
Jul 20, 2026
Merged

fix(schema-input): report clean fetch error for missing schema paths#2967
schani merged 1 commit into
masterfrom
agent/fix-issue-2812

Conversation

@schani

@schani schani commented Jul 20, 2026

Copy link
Copy Markdown
Member

Bug

--src-lang schema crashed with an unhelpful internal-error panic when given
a source path that doesn't exist:

$ node dist/index.js --src-lang schema --lang typescript --just-types --src '*.json'
Error: Internal error: Defined value expected, but got undefined.

This typically bites Windows/PowerShell users, whose shell doesn't expand
--src *.json the way POSIX shells do, so the literal, non-existent string
*.json is passed through to quicktype. For comparison, --src-lang json
with the same missing-path input gives a clean ENOENT error instead of a
panic.

Root cause

JSONSchemaStore.get (packages/quicktype-core/src/input/JSONSchemaStore.ts)
swallows the fetch error for a missing file and returns undefined.
Resolver.resolveVirtualRef (packages/quicktype-core/src/input/JSONSchemaInput.ts)
then calls schemaFetchError(base, virtualRef.address) to report the
failure — but virtualRef has no address in this case, and Ref.address
panics via defined() when addressURI is undefined. That panic is what
surfaces as "Internal error: Defined value expected, but got undefined."

Fix

Use virtualRef.toString() instead of virtualRef.address when building the
fetch-error message. toString() doesn't require an address (it degrades to
an empty string for the address portion), so building the error message no
longer panics. The CLI now reports a normal diagnostic:

$ node dist/index.js --src-lang schema --lang typescript --just-types --src '*.json'
Error: Could not fetch schema #, referred to from *.json#.

This is a minimal, one-line change scoped to the crash itself. CLI-side glob
expansion (the other defect discussed on the issue) is out of scope for this
PR.

Test coverage

Added test/unit/missing-schema-path.test.ts, a regression unit test that
drives JSONSchemaInput/FetchingJSONSchemaStore/quicktype() directly
(the same pattern used by test/unit/windows-schema-paths.test.ts for issue
#2869) to assert that a schema source pointing at a nonexistent path (a
literal wildcard, simulating what PowerShell passes through) rejects with a
normal "Could not fetch schema ..." error rather than throwing/panicking.
This is a unit test rather than a fixture test because the bug is about
error-handling/messaging for a missing input file, not about generated
output for valid input — exactly the kind of thing fixtures can't express.

Confirmed the test fails against the unfixed code (the panic message) and
passes after the fix.

Verification

  • npm run build passes.
  • npm run test:unit — all 164 unit tests pass, including the new
    regression test.
  • Manually re-ran the exact repro from the issue/triage comment and confirmed
    the internal-error panic no longer occurs; a clean fetch-error message is
    reported instead.
  • No fixture test was added since this change does not affect generated
    output for any valid input — CI will additionally validate the full
    fixture suite.

Fixes #2812

🤖 Generated with Claude Code

…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 <noreply@openai.com>
@schani
schani merged commit f77b9b9 into master Jul 20, 2026
28 checks passed
@schani
schani deleted the agent/fix-issue-2812 branch July 20, 2026 21:56
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.

[BUG]: using wildcard path on Windows CLI results in "Error: internal error: ."

1 participant