Skip to content

cz commands failed if there is already a config file but in wrong format #577

Closed
@Bogay

Description

@Bogay

Description

Run cz commands, e.g. cz init, cz version will fail if there is already a config file with default name but in wrong format.

Although this might not be a common case, IMO it would be better to tell users there is a wrong config (if cannot find others).

Steps to reproduce

mkdir /tmp/cz-init
cd /tmp/cz-init
echo "I am not json" > .cz.json
cz init

Current behavior

cz init failed caused by decode error. Outputs attached below.

Traceback (most recent call last):
  File "/home/bogay/.local/bin/cz", line 8, in <module>
    sys.exit(main())
  File "/home/bogay/.local/pipx/venvs/commitizen/lib/python3.8/site-packages/commitizen/cli.py", line 354, in main
    conf = config.read_cfg()
  File "/home/bogay/.local/pipx/venvs/commitizen/lib/python3.8/site-packages/commitizen/config/__init__.py", line 37, in read_cfg
    _conf = JsonConfig(data=data, path=filename)
  File "/home/bogay/.local/pipx/venvs/commitizen/lib/python3.8/site-packages/commitizen/config/json_config.py", line 14, in __init__
    self._parse_setting(data)
  File "/home/bogay/.local/pipx/venvs/commitizen/lib/python3.8/site-packages/commitizen/config/json_config.py", line 46, in _parse_setting
    doc = json.loads(data)
  File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Desired behavior

Maybe try to search the next possible config? If none of them are found. Report an error to user. Tell them there is a config with wrong format.

Screenshots

No response

Environment

Commitizen Version: 2.32.3
Python Version: 3.8.10 (default, Jun 22 2022, 20:18:18)
[GCC 9.4.0]
Operating System: Linux

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions