Skip to content

Commit

Permalink
Use a clearer message for nonexistent template branches
Browse files Browse the repository at this point in the history
  • Loading branch information
sarayourfriend committed Oct 17, 2024
1 parent 477e69c commit 5bf762a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
8 changes: 4 additions & 4 deletions src/briefcase/commands/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
from briefcase.exceptions import (
BriefcaseCommandError,
BriefcaseConfigError,
InvalidTemplateBranch,
InvalidTemplateRepository,
MissingAppMetadata,
NetworkFailure,
TemplateUnsupportedVersion,
UnsupportedHostError,
UnsupportedPythonVersion,
)
Expand Down Expand Up @@ -1037,7 +1037,7 @@ def update_cookiecutter_cache(self, template: str, branch="master"):
head.checkout()
except IndexError as e:
# No branch exists for the requested version.
raise TemplateUnsupportedVersion(branch) from e
raise InvalidTemplateBranch(template, branch) from e
except (ValueError, self.tools.git.exc.GitError) as e:
raise BriefcaseCommandError(
"Unable to check out template branch.\n"
Expand Down Expand Up @@ -1094,7 +1094,7 @@ def _generate_template(self, template, branch, output_path, extra_context):
raise InvalidTemplateRepository(template) from e
except cookiecutter_exceptions.RepositoryCloneFailed as e:
# Branch does not exist.
raise TemplateUnsupportedVersion(branch) from e
raise InvalidTemplateBranch(template, branch) from e
except cookiecutter_exceptions.UndefinedVariableInTemplate as e:
raise BriefcaseConfigError(e.message) from e

Expand Down Expand Up @@ -1135,7 +1135,7 @@ def generate_template(
output_path=output_path,
extra_context=extra_context,
)
except TemplateUnsupportedVersion:
except InvalidTemplateBranch:
# Only use the main template if we're on a development branch of briefcase
# and the user didn't explicitly specify which branch to use.
if version.dev is None or branch is not None:
Expand Down
7 changes: 3 additions & 4 deletions src/briefcase/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,10 @@ def __init__(self, error_msg):
super().__init__(msg=error_msg, skip_logfile=True)


class TemplateUnsupportedVersion(BriefcaseCommandError):
def __init__(self, briefcase_version):
self.briefcase_version = briefcase_version
class InvalidTemplateBranch(BriefcaseCommandError):
def __init__(self, template_repo, branch):
super().__init__(
f"Could not find a template branch for Briefcase {briefcase_version}."
f"{branch} did not match any branches in template repository {template_repo}."
)


Expand Down
4 changes: 2 additions & 2 deletions tests/commands/base/test_update_cookiecutter_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest
from git import exc as git_exceptions

from briefcase.exceptions import BriefcaseCommandError, TemplateUnsupportedVersion
from briefcase.exceptions import BriefcaseCommandError, InvalidTemplateBranch

from ...utils import create_file

Expand Down Expand Up @@ -394,7 +394,7 @@ def test_cached_missing_branch_template(base_command, mock_git):
cached_path.mkdir(parents=True)

# Generating the template under there conditions raises an error
with pytest.raises(TemplateUnsupportedVersion):
with pytest.raises(InvalidTemplateBranch):
base_command.update_cookiecutter_cache(
template="https://example.com/magic/special-template.git",
branch="invalid",
Expand Down
6 changes: 3 additions & 3 deletions tests/commands/create/test_generate_app_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from briefcase.exceptions import (
BriefcaseCommandError,
BriefcaseConfigError,
InvalidTemplateBranch,
NetworkFailure,
TemplateUnsupportedVersion,
)


Expand Down Expand Up @@ -243,7 +243,7 @@ def test_default_template_dev_explicit_invalid_branch(
)

# Generate the template.
with pytest.raises(TemplateUnsupportedVersion):
with pytest.raises(InvalidTemplateBranch):
create_command.generate_app_template(myapp)

# Cookiecutter was invoked (once) with the expected template name and context.
Expand Down Expand Up @@ -651,7 +651,7 @@ def test_cached_missing_branch_template(monkeypatch, create_command, myapp):
mock_remote.refs.__getitem__.side_effect = IndexError

# Generating the template under there conditions raises an error
with pytest.raises(TemplateUnsupportedVersion):
with pytest.raises(InvalidTemplateBranch):
create_command.generate_app_template(myapp)


Expand Down
6 changes: 3 additions & 3 deletions tests/commands/new/test_new_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from briefcase.console import Console, Log
from briefcase.exceptions import (
BriefcaseCommandError,
InvalidTemplateBranch,
InvalidTemplateRepository,
TemplateUnsupportedVersion,
)


Expand Down Expand Up @@ -123,7 +123,7 @@ def test_new_app_missing_template(monkeypatch, new_command, tmp_path):
)

# Create the new app, using the default template. This raises an error.
with pytest.raises(TemplateUnsupportedVersion):
with pytest.raises(InvalidTemplateBranch):
new_command.new_app()

# App context is constructed
Expand Down Expand Up @@ -397,7 +397,7 @@ def test_new_app_with_invalid_template_branch(monkeypatch, new_command, tmp_path
)

# Create a new app, with a specific template; this raises an error
with pytest.raises(TemplateUnsupportedVersion):
with pytest.raises(InvalidTemplateBranch):
new_command.new_app(template="https://example.com/other.git")

# App context is constructed
Expand Down

0 comments on commit 5bf762a

Please sign in to comment.