Skip to content

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

Merged
httpdss merged 1 commit into
mainfrom
feature/abort-cleanly-on-fetch-error
Jun 27, 2026
Merged

[#165] Abort cleanly when remote or local file: content cannot be fetched#170
httpdss merged 1 commit into
mainfrom
feature/abort-cleanly-on-fetch-error

Conversation

@httpdss

@httpdss httpdss commented Jun 27, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes #165.

When a file: item referenced content that could not be fetched, the error was logged but silently suppressed. Generation then continued with self.content unset, causing a secondary Jinja2 TypeError traceback that hid the original root cause.

Changes

structkit/file_item.py

  • Introduced ContentFetchError — a clean domain exception for content fetch failures.
  • FileItem.fetch_content() now raises ContentFetchError instead of logging and suppressing the exception.

structkit/commands/generate.py

  • Imported ContentFetchError from file_item.
  • GenerateCommand.execute() catches ContentFetchError alongside GenerateConfigError and TemplateVariableError, logging only the root-cause message and exiting with code 1.

tests/test_commands_more.py

  • Added test_generate_missing_local_file_ref_exits_cleanly: verifies a missing file:// target exits 1 with a clean root-cause message, no Traceback, and no output file created.
  • Added test_generate_remote_fetch_failure_exits_cleanly: verifies a mocked remote HTTP fetch failure exits 1 cleanly with the same guarantees.

Acceptance criteria

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

Introduce ContentFetchError to represent fetch failures cleanly.
FileItem.fetch_content() now raises ContentFetchError instead of
logging and suppressing exceptions, preventing a secondary Jinja2
TypeError traceback from obscuring the root cause.

GenerateCommand.execute() catches ContentFetchError alongside
GenerateConfigError and TemplateVariableError, logging only the
root-cause message and exiting with code 1.

Closes #165
@httpdss httpdss merged commit ceeb44c into main Jun 27, 2026
3 checks passed
@httpdss httpdss deleted the feature/abort-cleanly-on-fetch-error branch June 27, 2026 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant