Skip to content

fix(template): exit non-zero on errors and keep --json output pure - #23

Open
rahul05ranjan wants to merge 1 commit into
barisgit:mainfrom
rahul05ranjan:fix/template-exit-codes
Open

rahul05ranjan wants to merge 1 commit into
barisgit:mainfrom
rahul05ranjan:fix/template-exit-codes

Conversation

@rahul05ranjan

@rahul05ranjan rahul05ranjan commented Oct 22, 2026 •

Copy link
Copy Markdown

What

template create and template make reported their errors on the console and still exited 0, and template list --json could emit non-JSON to stdout (all of #18):

  • create: no templates configured, unknown --template, cancelled selection, undeterminable project directory, and failed project creation all exited 0. They now exit 1.
  • make: the missing-library-path case and "template already exists" without --force exited 0. They now exit 1 (the no-GitHub-library case already did).
  • template list --json with no templates printed the rich "no templates" panel to stdout instead of JSON. It now prints {}.
  • The root update notice now goes to stderr (stderr flag added to UpdateService.show_update_notification), so a JSON stdout stays pure while the notice stays visible in the terminal.
  • The hook script written into new templates printed its own "Project … created successfully!" next to create's success message; the print is now a commented example like the rest of the starter hook.

Why

Exit code 0 on failure breaks scripts that chain these commands, and a --json mode that can emit a rich panel (or an update panel) to stdout breaks any parser reading the output.

Verification

An offline harness ran the real create/make/list_templates command functions (dependencies stubbed) before and after the change, each against an isolated $HOME:

check before after
create, no templates configured returns, exit 0 typer.Exit(1)
create --template missing returns, exit 0 typer.Exit(1)
create, selection cancelled returns, exit 0 typer.Exit(1)
make --non-interactive onto existing template returns, exit 0 typer.Exit(1)
_complete_without_prompts with no library path make returns, exit 0 typer.Exit(1)
list --json, no templates rich panel repr on stdout {} (parses as JSON)
root update notice stdout stderr

New CLI tests pin the four reachable cases (no templates, --template missing, cancelled selection, make onto an existing template) plus the empty-JSON case, and test_starting_hook_runs now asserts the silent starter hook. Docs (commands/template/docs.mdx) document the new exit statuses and the --json guarantee.

Fixes #18

Summary by CodeRabbit

  • Bug Fixes
    • Template creation and generation now return a failure status when required templates or destinations are unavailable, selection is cancelled or invalid, or creation cannot complete. Existing templates are not overwritten without --force.
    • Empty template listings in JSON mode now return {} without mixing in a text message.
    • Update notices are written to standard error, keeping standard output available for JSON.
    • Newly generated post-creation hooks no longer print example messages by default.
  • Documentation
    • Clarified template command failure conditions and JSON output behavior.

`template create` and `template make` explained their errors on the
console and still exited 0: no templates configured, an unknown or
cancelled template selection, a project directory that could not be
determined, a failed project creation, and an existing template
without --force. Each now reports the problem as before and exits
with status 1, the convention the other commands already follow.

`template list --json` printed the rich "no templates" panel instead
of JSON when no library had templates; it now answers with an empty
object. The root update notice moves to stderr (new `stderr` flag on
`UpdateService.show_update_notification`) so JSON output on stdout
stays pure, and the hook script written into new templates no longer
prints a second success message next to `template create`'s own.

Fixes barisgit#18

Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com>
@vercel

vercel Bot commented Oct 22, 2026

Copy link
Copy Markdown

@rahul05ranjan is attempting to deploy a commit to the Paxia LLC Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 49959357-6438-4467-98e2-3e7d2291403c
📥 Commits

Reviewing files that changed from the base of the PR and between a3d8ef1 and 4701c7a.

📒 Files selected for processing: 9
  • kicad_lib_manager/commands/template/create.py
  • kicad_lib_manager/commands/template/docs.mdx
  • kicad_lib_manager/commands/template/listing.py
  • kicad_lib_manager/commands/template/make.py
  • kicad_lib_manager/main.py
  • kicad_lib_manager/services/update_service.py
  • kicad_lib_manager/utils/template/hooks.py
  • tests/test_template.py
  • tests/test_template_commands.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Walkthrough

Template commands now return status 1 for covered failures. Empty JSON template listings emit {}, and update notices use stderr. Generated post-creation hooks no longer print the project name or location by default.

Changes: Template CLI behavior

Layer / File(s) Summary
Template command failure handling
kicad_lib_manager/commands/template/create.py, kicad_lib_manager/commands/template/make.py, kicad_lib_manager/commands/template/docs.mdx, tests/test_template_commands.py
The create and make commands now exit with status 1 on covered failure paths. Documentation and CLI tests describe or check these outcomes.
JSON output and update notice routing
kicad_lib_manager/commands/template/listing.py, kicad_lib_manager/services/update_service.py, kicad_lib_manager/main.py, kicad_lib_manager/commands/template/docs.mdx, tests/test_template_commands.py
An empty JSON template listing emits {}. Update notices are sent to stderr through the new stderr option. The documentation and CLI test cover JSON output.
Generated hook output
kicad_lib_manager/utils/template/hooks.py, tests/test_template.py
The generated hook’s example print calls are commented out. The test expects no hook output after creation.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: barisgit

Merge Risk: ⚪ Minimal · up to 4701c

No identified issue remains that should delay merging the template command changes.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely summarizes the main changes: template commands now exit non-zero on errors, and --json output remains pure.
Linked Issues check Passed Issue #18 coding requirements are implemented. template create raises typer.Exit(1) for no templates, an unknown or cancelled selection, cancelled variables, an undetermined directory, declined ov…
Out of Scope Changes check Passed The changes stay within issue #18. The code changes affect the two template commands, JSON listing output, update-notice routing, and the generated template hook. The added tests and documentation ver…
Docstring Coverage Passed Docstring coverage is 87.50% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 8 files. (1 skipped: 1 …
Full details: Linked Issues check

Explanation

Issue #18 coding requirements are implemented. template create raises typer.Exit(1) for no templates, an unknown or cancelled selection, cancelled variables, an undetermined directory, declined overwrite through _prepare_project_directory, and project creation failure. template make raises status 1 for a missing library path and an existing destination without --force. Empty template list --json output is {}, and update notices use stderr. The generated hook no longer prints a duplicate success message. The supplied evidence reports CLI tests for the requested command cases and documentation for the contract.

Full details: Out of Scope Changes check

Explanation

The changes stay within issue #18. The code changes affect the two template commands, JSON listing output, update-notice routing, and the generated template hook. The added tests and documentation verify these behaviors. No unrelated change is established.

Full details: Docstring Coverage

Explanation

Docstring coverage is 87.50% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 8 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checks the template tray,
No empty list spoils JSON today.
A quiet hook makes no display,
Failed commands now mark the way,
Then hops through fields of green and gray.

Comment @coderabbitai help to get the list of available commands.

@rahul05ranjan

Copy link
Copy Markdown
Author

Hi — Vercel authorization is needed for the preview. Ready for review otherwise!

This branch has not been deployed

No deployments
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.

template create/make exit 0 on errors, and template list --json can emit invalid JSON

1 participant