Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid exception traceback with "towncrier check" #336

Closed
tomschr opened this issue Apr 6, 2021 · 7 comments · Fixed by #501
Closed

Avoid exception traceback with "towncrier check" #336

tomschr opened this issue Apr 6, 2021 · 7 comments · Fixed by #501

Comments

@tomschr
Copy link
Contributor

tomschr commented Apr 6, 2021

Situation

When calling towncrier check in a directory without any Towncrier config files, you get this exception:

$ mkdir /tmp/towncrier-test; cd /tmp/towncrier-test
$ python3 -m venv .env
$ source .env/bin/activate
$ .env/bin/pip install towncrier
$ pip show towncrier
Name: towncrier
Version: 21.3.0
[...]
Location: /tmp/towncrier-test/.env/lib/python3.6/site-packages
$ .env/bin/towncrier check
Traceback (most recent call last):
  File ".env/bin/towncrier", line 8, in <module>
    sys.exit(cli())
  File "/tmp/towncrier-test/.env/lib64/python3.6/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/tmp/towncrier-test/.env/lib64/python3.6/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/tmp/towncrier-test/.env/lib64/python3.6/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/tmp/towncrier-test/.env/lib64/python3.6/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/tmp/towncrier-test/.env/lib64/python3.6/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/tmp/towncrier-test/.env/lib64/python3.6/site-packages/towncrier/check.py", line 27, in _main
    return __main(compare_with, directory, config)
  File "/tmp/towncrier-test/.env/lib64/python3.6/site-packages/towncrier/check.py", line 32, in __main
    base_directory, config = load_config_from_options(directory, config)
  File "/tmp/towncrier-test/.env/lib64/python3.6/site-packages/towncrier/_settings.py", line 49, in load_config_from_options
    "No configuration file found.\nLooked in: %s" % (base_directory,)
towncrier._settings.ConfigError: No configuration file found.
Looked in: /tmp/towncrier-test

Proposed solution

The traceback shouldn't be displayed. Don't frighten our users. 😉 IMHO it's completely enough if we catch it and output only the error message:

$ .env/bin/towncrier check
towncrier._settings.ConfigError: No configuration file found.
Looked in: /tmp/towncrier-test
$ echo $?
1

Possible dependencies

Maybe related to #306

@adiroiban
Copy link
Member

Thanks the report. Agree.
I also think that this is related to #306

As commented in 306, either use click exception, or add code to handle towncrier._settings.ConfigError

For this particular case maybe raise click.FileError ? https://click.palletsprojects.com/en/7.x/exceptions/#which-exceptions-exist

@chrysle
Copy link
Contributor

chrysle commented Feb 28, 2023

Can I work on this?

@adiroiban
Copy link
Member

Hi @chrysle

You are welcome to give this a try.

You can create a PR and write the minimal test for it to check that the full traceback is no longer visible.

@chrysle
Copy link
Contributor

chrysle commented Mar 3, 2023

For this particular case maybe raise click.FileError ? https://click.palletsprojects.com/en/7.x/exceptions/#which-exceptions-exist

I don't think this will be much less frightening (?):

Error: Could not open file '/home/user': unknown error

@chrysle
Copy link
Contributor

chrysle commented Mar 4, 2023

The problem is that if the config_path is None, only base_directory can be passed to the exception.

It would maybe be better just to print:

No configuration file found.\nLooked in: {base_directory}

@adiroiban
Copy link
Member

The last suggestion is ok.
I think that the main issue here is that the ConfigError is not handled/caught so we have the traceback.
Thanks

@chrysle
Copy link
Contributor

chrysle commented Mar 7, 2023

@adiroiban Could you make a suggestion for a test?

My problem is that there is no suitable assert in the trial assertions , like assertNotRaises.

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 a pull request may close this issue.

3 participants