Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b7b96f6

Browse files
committed
fix: improve errors message when empty .cz.json found
Closes #576
1 parent b0d8778 commit b7b96f6

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

‎commitizen/config/json_config.py‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
from pathlib import Path
33
from typing import Union
4+
from commitizen.exceptions import InvalidConfigurationError
45

56
from commitizen.git import smart_open
67

@@ -11,8 +12,8 @@ class JsonConfig(BaseConfig):
1112
def __init__(self, *, data: Union[bytes, str], path: Union[Path, str]):
1213
super(JsonConfig, self).__init__()
1314
self.is_empty_config = False
14-
self._parse_setting(data)
1515
self.add_path(path)
16+
self._parse_setting(data)
1617

1718
def init_empty_config_content(self):
1819
with smart_open(self.path, "a") as json_file:
@@ -43,7 +44,11 @@ def _parse_setting(self, data: Union[bytes, str]) -> None:
4344
}
4445
```
4546
"""
46-
doc = json.loads(data)
47+
try:
48+
doc = json.loads(data)
49+
except json.JSONDecodeError:
50+
raise InvalidConfigurationError(f"Failed to parse {self.path}")
51+
4752
try:
4853
self.settings.update(doc["commitizen"])
4954
except KeyError:

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /