Skip to content

Abort cleanly when remote or local file: content cannot be fetched #165

Closed

Description

@httpdss

Summary

When a file item references remote/local content that cannot be fetched, StructKit logs the fetch error but continues generation with self.content unset. That leads to a secondary Jinja2 TypeError traceback that hides the original root cause.

Evidence

Observed locally with a structure like:

files:
  - out.txt:
      file: file:///tmp/does-not-exist.txt

The CLI first logs the useful root cause:

❗ Failed to fetch content from file:///tmp/.../does-not-exist.txt: [Errno 2] No such file or directory

Then continues and crashes later:

Traceback ...
self.content = self.template_renderer.render_template(self.content, vars)
...
TypeError: Can't compile non template nodes

Relevant code:

  • structkit/file_item.py:75-92 catches all exceptions in fetch_content, logs, and suppresses them.
  • GenerateCommand._create_structure then calls file_item.apply_template_variables(...) even though content was not loaded.

Proposed fix

  • Introduce a domain error such as ContentFetchError for content fetch failures.
  • Do not suppress fetch failures in FileItem.fetch_content; propagate a clean error to the command boundary.
  • GenerateCommand should catch expected content-fetch errors and exit 1 with only the root cause, no secondary traceback.
  • Avoid creating or modifying output files after a required content fetch fails.

Acceptance criteria

  • Missing file:// target exits 1 with a clean root-cause message and no Traceback.
  • HTTP/GitHub/S3/GCS fetch failures report source and error category cleanly.
  • Generation stops immediately on required fetch failures.
  • Tests cover at least missing local file:// and one mocked remote failure.

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