Skip to content

Commit 6c7a78b

Browse files
Don't dump full stack trace when there are file validation errors (#768)
1 parent 3b81c72 commit 6c7a78b

4 files changed

Lines changed: 35 additions & 4 deletions

File tree

src/usethis/_integrations/ci/bitbucket/io_.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from usethis._console import tick_print
1111
from usethis._integrations.ci.bitbucket.schema import PipelinesConfiguration
1212
from usethis._integrations.file.yaml.io_ import edit_yaml
13+
from usethis.errors import FileConfigError
1314

1415
if TYPE_CHECKING:
1516
from collections.abc import Generator
@@ -20,9 +21,14 @@
2021
from usethis._integrations.file.yaml.io_ import YAMLLiteral
2122

2223

23-
class BitbucketPipelinesYAMLConfigError(Exception):
24+
class BitbucketPipelinesYAMLConfigError(FileConfigError):
2425
"""Raised when there the 'bitbucket-pipelines.yml' file fails validation."""
2526

27+
@property
28+
def name(self) -> str:
29+
"""The name of the file that has a configuration error."""
30+
return "bitbucket-pipelines.yml"
31+
2632

2733
@dataclass
2834
class BitbucketPipelinesYAMLDocument:

src/usethis/_integrations/file/pyproject_toml/errors.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
UnexpectedTOMLIOError,
1010
UnexpectedTOMLOpenError,
1111
)
12+
from usethis.errors import FileConfigError
1213

1314

1415
class PyprojectTOMLError(TOMLError):
@@ -40,9 +41,14 @@ class UnexpectedPyprojectTOMLIOError(PyprojectTOMLError, UnexpectedTOMLIOError):
4041
"""Raised when an unexpected attempt is made to read or write the pyproject.toml file."""
4142

4243

43-
class PyprojectTOMLProjectSectionError(PyprojectTOMLError):
44+
class PyprojectTOMLProjectSectionError(FileConfigError, PyprojectTOMLError):
4445
"""Raised when the 'project' section is missing or invalid in 'pyproject.toml'."""
4546

47+
@property
48+
def name(self) -> str:
49+
"""The name of the file that has a configuration error."""
50+
return "pyproject.toml"
51+
4652

4753
class PyprojectTOMLProjectNameError(PyprojectTOMLProjectSectionError):
4854
"""Raised when the 'project.name' key is missing or invalid in 'pyproject.toml'."""

src/usethis/_integrations/pre_commit/io_.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from usethis._console import tick_print
1111
from usethis._integrations.file.yaml.io_ import edit_yaml
1212
from usethis._integrations.pre_commit.schema import JsonSchemaForPreCommitConfigYaml
13+
from usethis.errors import FileConfigError
1314

1415
if TYPE_CHECKING:
1516
from collections.abc import Generator
@@ -19,9 +20,14 @@
1920
from usethis._integrations.file.yaml.io_ import YAMLLiteral
2021

2122

22-
class PreCommitConfigYAMLConfigError(Exception):
23+
class PreCommitConfigYAMLConfigError(FileConfigError):
2324
"""Raised when there the 'bitbucket-pipelines.yml' file fails validation."""
2425

26+
@property
27+
def name(self) -> str:
28+
"""The name of the file that has a configuration error."""
29+
return ".pre-commit-config.yaml"
30+
2531

2632
@dataclass
2733
class PreCommitConfigYAMLDocument:

src/usethis/errors.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,20 @@ class UsethisError(Exception):
77
"""Base class for all errors."""
88

99

10-
class FileDecodeError(UsethisError):
10+
class FileConfigError(UsethisError):
11+
"""Raised when there is an error in a file configuration."""
12+
13+
@property
14+
def name(self) -> str:
15+
"""The name of the file that has a configuration error.
16+
17+
This is not necessarily defined for all subclasses, and will raise
18+
NotImplementedError if not overridden.
19+
"""
20+
raise NotImplementedError
21+
22+
23+
class FileDecodeError(FileConfigError):
1124
"""Raised when a file is unexpectedly not decodable."""
1225

1326
@property

0 commit comments

Comments
 (0)