Skip to content

fix: hint at pathlib.Path when load_schema gets a non-JSON str - #26

Merged
jnsdls merged 1 commit into
mainfrom
t3code/triage-issue-23
Oct 15, 2026
Merged

jnsdls merged 1 commit into
mainfrom
t3code/triage-issue-23

Conversation

@jnsdls

@jnsdls jnsdls commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Summary

load_schema reads a str as JSON text and only reads a file when given a pathlib.Path. Passing a path as a str used to fail with a bare decode error. That error now says to pass a Path.

 load_schema(source)
   if Path: parse file contents
   elif str:
-    json.loads(source)
+    try json.loads(source)
+    except JSONDecodeError as e:
+      raise JSONDecodeError(e.msg + " (a str is JSON text; pass a pathlib.Path to read a file)") from e
   validate as Schema

It still raises JSONDecodeError, a ValueError subclass, so except ValueError and except json.JSONDecodeError handlers catch it as before. The original error is kept as __cause__.

Closes #23

Evidence

  • Before: load_schema("schema.json") raised JSONDecodeError: Expecting value: line 1 column 1 (char 0), and test_load_schema_str_that_is_not_json_hints_at_path failed.
    After: load_schema("schema.json") raises JSONDecodeError: Expecting value (a str is JSON text; pass a pathlib.Path to read a file): line 1 column 1 (char 0). The test passes, and the full suite passes (202 tests, 100% coverage).

Merge Danger

Door: two-way

Blast Radius: tiny

Only the error message for a bad str changes. Code that matches on the exact old message text would no longer match.

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

load_schema parses a str as JSON text, so passing a file path as a str
failed with a bare "Expecting value" decode error. The error is now still
a JSONDecodeError, chained from the original, and says to pass a
pathlib.Path to read a file.

Closes #23

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jnsdls
jnsdls merged commit c230f94 into main Oct 15, 2026
5 checks passed
@jnsdls
jnsdls deleted the t3code/triage-issue-23 branch October 15, 2026 19:08
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.

load_schema reads a str path as JSON text and fails with a decode error

1 participant