Skip to content

Commit d626a90

Browse files
authored
No traceback on missing configuration with towncrier check (#501)
1 parent daac2d2 commit d626a90

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/towncrier/_settings/load.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
from pathlib import Path
1414
from typing import TYPE_CHECKING, Any, Mapping, Sequence
1515

16+
from click import ClickException
17+
1618
from .._settings import fragment_types as ft
1719

1820

@@ -60,7 +62,7 @@ class Config:
6062
orphan_prefix: str = "+"
6163

6264

63-
class ConfigError(Exception):
65+
class ConfigError(ClickException):
6466
def __init__(self, *args: str, **kwargs: str):
6567
self.failing_option = kwargs.get("failing_option")
6668
super().__init__(*args)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Calling ``towncrier check`` without an existing configuration, will just show only an error message.
2+
3+
In previous versions, a traceback was generated instead of the error message.

src/towncrier/test/test_settings.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33

44
import os
55

6+
from click.testing import CliRunner
67
from twisted.trial.unittest import TestCase
78

89
from .._settings import ConfigError, load_config
9-
from .helpers import write
10+
from .._shell import cli
11+
from .helpers import with_isolated_runner, write
1012

1113

1214
class TomlSettingsTests(TestCase):
@@ -192,6 +194,23 @@ def test_towncrier_toml_preferred(self):
192194
config = load_config(project_dir)
193195
self.assertEqual(config.package, "a")
194196

197+
@with_isolated_runner
198+
def test_load_no_config(self, runner: CliRunner):
199+
"""
200+
Calling the root CLI without an existing configuration file in the base directory,
201+
will exit with code 1 and an informative message is sent to standard output.
202+
"""
203+
temp = self.mktemp()
204+
os.makedirs(temp)
205+
206+
result = runner.invoke(cli, ("--dir", temp))
207+
208+
self.assertEqual(
209+
result.output,
210+
f"No configuration file found.\nLooked in: {os.path.abspath(temp)}\n",
211+
)
212+
self.assertEqual(result.exit_code, 1)
213+
195214
def test_missing_template(self):
196215
"""
197216
Towncrier will raise an exception saying when it can't find a template.

0 commit comments

Comments
 (0)