Skip to content

Harden template-loader error handling and reduce duplication#50

Closed
zevorn wants to merge 1 commit intoPolyArch:mainfrom
zevorn:fix/template-loader-robustness
Closed

Harden template-loader error handling and reduce duplication#50
zevorn wants to merge 1 commit intoPolyArch:mainfrom
zevorn:fix/template-loader-robustness

Conversation

@zevorn
Copy link
Copy Markdown

@zevorn zevorn commented Mar 18, 2026

Summary

  • Remove spurious blank stderr line from load_template when template file is missing (was echo "" >&2 before the warning message, polluting stderr output)
  • Add awk exit code propagation in render_template — if the awk substitution engine fails, the error is now surfaced to stderr and the function returns non-zero instead of silently producing empty output
  • Extract _emit_fallback helper to eliminate duplicated fallback emission logic in load_and_render_safe (same 5-line pattern was repeated twice)
  • Guard append_template against appending empty content when the additional template is missing (previously appended an empty line unconditionally)
  • Extend validate_template_dir to check all 5 required subdirectories (block, codex, claude, plan, pr-loop) — previously only checked the first 3

All existing tests pass (43/43 template-loader tests, 104/104 template-reference checks).

Test plan

  • bash tests/test-template-loader.sh — all 43 tests pass
  • bash tests/test-template-references.sh — all 104 checks pass, 0 failures
  • Verify no behavioral regression in RLCR loop stop hook flow
  • Verify load_and_render_safe fallback still works correctly in validators

- Remove spurious blank stderr line from load_template on missing files
- Add awk exit code propagation in render_template to surface failures
- Extract _emit_fallback helper to deduplicate load_and_render_safe
- Prevent append_template from appending empty content on missing templates
- Extend validate_template_dir to check all required subdirs (plan, pr-loop)
- Bump version to 1.14.1

Signed-off-by: Chao Liu <chao.liu.zevorn@gmail.com>
SihaoLiu added a commit that referenced this pull request Mar 29, 2026
…ation

- Remove spurious blank stderr line from load_template
- Add awk exit code propagation in render_template
- Extract _emit_fallback helper to eliminate duplicated fallback logic
- Guard append_template against appending empty content
- Extend validate_template_dir to check all 5 required subdirectories
@SihaoLiu
Copy link
Copy Markdown
Contributor

Merged into dev branch via local merge (commit 1862329). Template-loader hardening applied.

@SihaoLiu SihaoLiu closed this Mar 29, 2026
@SihaoLiu SihaoLiu mentioned this pull request Mar 29, 2026
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.

2 participants