Skip to content

Make --input-store errors user-friendly, including relative paths and corrupt JSON #166

Closed

Description

@httpdss

Summary

The input store implementation assumes --input-store has a directory component and valid JSON. Relative filenames such as --input-store input.json, unreadable paths, or corrupt JSON can currently produce raw Python exceptions during generation.

Evidence

Observed locally:

python -m structkit.main generate --non-interactive --input-store input.json simple.yaml out
Traceback ...
FileNotFoundError: [Errno 2] No such file or directory: ''

Relevant code:

  • structkit/input_store.py:12-14 calls os.makedirs(os.path.dirname(input_file)); for input.json, os.path.dirname(...) is ''.
  • InputStore.load directly calls json.load, so corrupt JSON would raise json.JSONDecodeError as a traceback.
  • These errors surface from TemplateRenderer/FileItem construction rather than a clean CLI message.

Proposed fix

  • Treat an empty dirname as current directory and avoid os.makedirs('').
  • Catch json.JSONDecodeError and OSError with a clean InputStoreError message.
  • Catch that domain error in commands/tools that construct TemplateRenderer.
  • Include the input-store path in error messages.

Acceptance criteria

  • --input-store input.json works and creates/uses ./input.json.
  • Corrupt input-store JSON exits 1 with a clean message and no Traceback.
  • Permission/read/write errors for the input store include the path and exit 1 cleanly.
  • Tests cover relative path, corrupt JSON, and unwritable/read-error path where practical.

Activity

  1. added a commit that references this issue on Jun 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions