Skip to content

Display an error screen when the template repository is not usable - #211

Merged
ericof merged 1 commit into
1.xfrom
issue-210
Aug 10, 2026
Merged

Display an error screen when the template repository is not usable#211
ericof merged 1 commit into
1.xfrom
issue-210

Conversation

@ericof

@ericof ericof commented Aug 10, 2026

Copy link
Copy Markdown
Member

What

Display an error screen, instead of a traceback, when the template repository cannot be used, and pin the default --tag for the 1.x series.

Why

cookieplone resolved the base repository with a bare call to get_base_repository, so any failure surfaced as a raw cookiecutter traceback.

Two distinct failures reach that call:

  • RepositoryNotFound — no candidate directory contains a cookiecutter.json file at its root (determine_repo_dir checks repository_has_cookiecutter_json for each candidate before raising).
  • RepositoryCloneFailed — the clone succeeded but the requested tag does not exist (cookiecutter.vcs.clone raises this on a failed checkout).

The second is the case the error message actually steers the user toward ("use another tag"), so handling only the first would leave that advice unreachable.

How

  • New get_repository_or_exit helper in cookieplone/cli.py wraps get_base_repository, catches both exceptions, renders an error screen, and exits with status 1. Keeping the handling in a helper also holds cli under the McCabe complexity limit enforced by ruff.
  • New console.error_screen renders a message inside the standard cookieplone panel.
  • Default --tag pinned to 20260810.1, an existing tag of plone/cookieplone-templates.

Tests

  • tests/test_cli.py — parametrized over RepositoryNotFound and RepositoryCloneFailed; asserts exit code 1 and that the error screen is displayed.
  • tests/utils/test_console.py — renders the panel through a recording rich.Console and asserts its title and message.

Verified the RepositoryCloneFailed case fails without the fix by temporarily narrowing the except clause, then restoring it.

Full suite: 280 passed. make lint clean.

Notes

Targets the 1.x maintenance branch.

Refs #210

Resolve the base repository through a new `get_repository_or_exit` helper,
which catches `RepositoryNotFound` and `RepositoryCloneFailed` and displays
an error screen instead of letting a traceback reach the user.

`RepositoryNotFound` is raised when no candidate directory contains a
`cookiecutter.json` file at its root, and `RepositoryCloneFailed` when the
requested tag does not exist -- the latter is the case the error message
points at, so both need to be handled.

Keeping the handling in a helper also holds `cli` under the McCabe
complexity limit enforced by ruff.

Pin the default `--tag` to `20260810.1`.

Refs #210
@ericof
ericof merged commit d4d980c into 1.x Aug 10, 2026
7 checks passed
@ericof
ericof deleted the issue-210 branch August 10, 2026 20:36
Comment thread cookieplone/cli.py
typer.Option("--output-dir", "-o", help="Where to generate the code."),
] = None,
tag: Annotated[str, typer.Option(help="Tag.")] = "main",
tag: Annotated[str, typer.Option(help="Tag.")] = "20260810.1",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ericof Hmm. So if we need to release a bugfix for the 1.x templates, how will we do that? We'll need to make a new release of cookieplone 1.x with a new default tag here? And what happens once we are making releases of the next templates as well? Using calver here makes it hard to have 2 parallel sets of releases for 1.x and next.

Answering my own question: we don't intend to maintain the 1.x templates once next is released. The goal here is to make sure that the last cookieplone 1.x release doesn't pick up the new templates that it doesn't know how to handle, not to have 2 active maintenance branches.

By the way, something went wrong with the release notes: https://github.com/plone/cookieplone-templates/releases/tag/20260810.1

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