fix(schema-input): report clean fetch error for missing schema paths#2967
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
--src-lang schemacrashed with an unhelpful internal-error panic when givena source path that doesn't exist:
This typically bites Windows/PowerShell users, whose shell doesn't expand
--src *.jsonthe way POSIX shells do, so the literal, non-existent string*.jsonis passed through to quicktype. For comparison,--src-lang jsonwith the same missing-path input gives a clean
ENOENTerror instead of apanic.
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 thefailure — but
virtualRefhas no address in this case, andRef.addresspanics via
defined()whenaddressURIisundefined. That panic is whatsurfaces as "Internal error: Defined value expected, but got undefined."
Fix
Use
virtualRef.toString()instead ofvirtualRef.addresswhen building thefetch-error message.
toString()doesn't require an address (it degrades toan empty string for the address portion), so building the error message no
longer panics. The CLI now reports a normal diagnostic:
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 thatdrives
JSONSchemaInput/FetchingJSONSchemaStore/quicktype()directly(the same pattern used by
test/unit/windows-schema-paths.test.tsfor 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 buildpasses.npm run test:unit— all 164 unit tests pass, including the newregression test.
the internal-error panic no longer occurs; a clean fetch-error message is
reported instead.
output for any valid input — CI will additionally validate the full
fixture suite.
Fixes #2812
🤖 Generated with Claude Code