beeware / briefcase

Tools to support converting a Python project into a standalone native application.
https://briefcase.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
2.57k stars 363 forks source link

Improve Error Handling for Invalid Briefcase Template #1118

Open rmartin16 opened 1 year ago

rmartin16 commented 1 year ago

What is the problem or limitation you are having?

The error state for using an invalid remote repo can be improved. While the "invalid repo" example is completely manufactured, I encountered the non-existent repo one with a typo.

A non-existent repo

❯ briefcase new -t https://github.com/beeware/beeware-template.git --template-branch linux-system --no-input

Generating a new application 'Hello World'
Using app template: https://github.com/beeware/beeware-template.git, branch linux-system

Log saved to /home/russell/tmp/beeware/logs/briefcase.2023_03_05-16_19_56.new.log

Traceback (most recent call last):
  File "/home/russell/github/beeware/briefcase/venv-3.10-briefcase/bin/briefcase", line 8, in <module>
    sys.exit(main())
  File "/home/russell/github/beeware/briefcase/src/briefcase/__main__.py", line 20, in main
    command(**options)
  File "/home/russell/github/beeware/briefcase/src/briefcase/commands/new.py", line 528, in __call__
    return self.new_app(
  File "/home/russell/github/beeware/briefcase/src/briefcase/commands/new.py", line 477, in new_app
    self.generate_template(
  File "/home/russell/github/beeware/briefcase/src/briefcase/commands/base.py", line 814, in generate_template
    cached_template = self.update_cookiecutter_cache(
  File "/home/russell/github/beeware/briefcase/src/briefcase/commands/base.py", line 758, in update_cookiecutter_cache
    remote = repo.remote(name="origin")
  File "/home/russell/github/beeware/briefcase/venv-3.10-briefcase/lib/python3.10/site-packages/git/repo/base.py", line 414, in remote
    raise ValueError("Remote named '%s' didn't exist" % name)
ValueError: Remote named 'origin' didn't exist

An invalid repo

❯ briefcase new -t https://example.com --template-branch linux-system --no-input

Generating a new application 'Hello World'
Using app template: https://example.com, branch linux-system

Log saved to /home/russell/tmp/beeware/logs/briefcase.2023_03_05-16_20_46.new.log

Traceback (most recent call last):
  File "/home/russell/github/beeware/briefcase/venv-3.10-briefcase/bin/briefcase", line 8, in <module>
    sys.exit(main())
  File "/home/russell/github/beeware/briefcase/src/briefcase/__main__.py", line 20, in main
    command(**options)
  File "/home/russell/github/beeware/briefcase/src/briefcase/commands/new.py", line 528, in __call__
    return self.new_app(
  File "/home/russell/github/beeware/briefcase/src/briefcase/commands/new.py", line 477, in new_app
    self.generate_template(
  File "/home/russell/github/beeware/briefcase/src/briefcase/commands/base.py", line 820, in generate_template
    self.tools.cookiecutter(
  File "/home/russell/github/beeware/briefcase/venv-3.10-briefcase/lib/python3.10/site-packages/cookiecutter/main.py", line 69, in cookiecutter
    repo_dir, cleanup = determine_repo_dir(
  File "/home/russell/github/beeware/briefcase/venv-3.10-briefcase/lib/python3.10/site-packages/cookiecutter/repository.py", line 106, in determine_repo_dir
    cloned_repo = clone(
  File "/home/russell/github/beeware/briefcase/venv-3.10-briefcase/lib/python3.10/site-packages/cookiecutter/vcs.py", line 72, in clone
    repo_type, repo_url = identify_repo(repo_url)
  File "/home/russell/github/beeware/briefcase/venv-3.10-briefcase/lib/python3.10/site-packages/cookiecutter/vcs.py", line 45, in identify_repo
    raise UnknownRepoType
cookiecutter.exceptions.UnknownRepoType

Describe the solution you'd like

Catch these errors and inform the user to verify the template.

Describe alternatives you've considered

Interpret the errors myself.

Additional context

briefcase.2023_03_05-16_19_56.new.log briefcase.2023_03_05-16_20_46.new.log

Kaushal-Dhungel commented 1 year ago

HI, Can I work on this ?

freakboy3742 commented 1 year ago

@Kaushal-Dhungel Absolutely! We don't have a formal issue assignment or claim process; if an issue is open, it's available to be worked on. Just drop a comment on the ticket to let others know you're looking at it, so we don't end up with duplicated effort.

rmblau commented 1 year ago

This will be partially handled by https://github.com/beeware/briefcase/pull/1210

tiffanyxiao commented 3 months ago

Hi, I will try to tackle this issue for Pycon2024 🐝

rmblau commented 3 months ago

Hi, I will try to tackle this issue for Pycon2024 🐝

I will be excited to see what you can do to fully handle it!

tiffanyxiao commented 3 months ago

After some initial digging around, it looks like the first case no longer triggers the same ValueError but the second still triggers the cookiecutter.exceptions.UnknownRepoType. I think its still worthwhile to make the second error message more descriptive, as it took some more digging to understand what a repo "type" is (at least in terms of cookie cutter). Initially while reading this issue, I also wasn't sure what qualified as an invalid repo.

Could I work on writing a more descriptive error message for the UnknownRepoType? What are others thoughts on this?

rmartin16 commented 3 months ago

FWIW, I think I'd be inclined to simply catch any exception that cookiecutter could throw; I'm not sure there's much value in pushing such exceptions to users who are not likely to even know cookiecutter is involved.