Skip to content

Avoid exception traceback with "towncrier check" #336

@tomschr

Description

@tomschr

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions