Skip to content

SchemaSerializer.Load throws ArgumentException on a .schema.json with an absolute outputPath or data source file, crashing kschema and the editor's File > Open #299

Closed

Description

@matt-edmondson

What's wrong

outputPath and file are deserialized through the semantic path types. An absolute value such as "outputPath": "/tmp/out" or "file": "C:\\data\\items.json" makes the converter throw ArgumentException.

SchemaSerializer.Load catches only JsonException (Schema/SchemaSerializer.cs:157 and :205). Open PR #297 adds NotSupportedException, but not ArgumentException. So the exception escapes to two callers:

  • kschema validate / kschema generate: neither SchemaCommandLine.TryLoad (Schema/Cli/SchemaCommandLine.cs:193) nor Schema.Tool/Program.cs catches it. The user gets a stack trace instead of "Could not open ...".
  • The editor: SchemaFile.Load (Schema.Editor/SchemaFile.cs:62-80) catches only IOException and UnauthorizedAccessException. Opening such a file, including from the recent-files list, throws out of the frame.

docs/schema-format.md says these paths are relative. Still, a hand-written or tool-written file with an absolute path is easy to produce. It should be refused as InvalidJson, not crash the process.

Repro

SchemaSerializer.Load(
    "{\"formatVersion\":1,\"codeGenerators\":[{\"name\":\"G\",\"language\":\"CSharp\",\"outputPath\":\"/tmp/out\"}]}",
    "/tmp/x.schema.json".As<AbsoluteFilePath>());
// throws ArgumentException: Cannot convert "/tmp/out" to RelativeDirectoryPath

Suggested fix / acceptance criteria

  • Load returns SchemaLoadStatus.InvalidJson with a message that names the property and says paths must be relative to the schema file. Either:
    • catch ArgumentException around the deserialize call, or
    • give the path properties a converter that reports a JsonException with the JSON path.
  • Tests for an absolute outputPath and for an absolute data source file:
    • Load returns InvalidJson;
    • kschema validate exits 1 with "Could not open".
  • Optional: state in schema-format.md that absolute paths are refused.

This is related to #242 and #287, which are other load crashes on different inputs. PR #297 does not cover this one.

Activity

  1. matt-edmondson commented on Oct 19, 2026

    @matt-edmondson
    ContributorAuthor

    Triage


    Generated by Claude Code

  2. added 2 commits that reference this issue on Oct 20, 2026
    67bced7
    c2de80e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions