Skip to content

cz init failed if there is already a config with identical filename (json format) #576

Closed
@Bogay

Description

@Bogay

Description

Run cz init failed if there is already a config with identical filename (json format).

Steps to reproduce

mkdir /tmp/cz-init
cd /tmp/cz-init
echo '{"foo": {}}' > .cz.json
cz init
# Select .cz.json as config file, other questions leave defaults

Current behavior

Initialization failed. Error outputs are 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 389, in main
    args.func(conf, vars(args))()
  File "/home/bogay/.local/pipx/venvs/commitizen/lib/python3.8/site-packages/commitizen/commands/init.py", line 40, in __call__
    self._update_config_file(values_to_add)
  File "/home/bogay/.local/pipx/venvs/commitizen/lib/python3.8/site-packages/commitizen/commands/init.py", line 157, in _update_config_file
    self.config.set_key(key, value)
  File "/home/bogay/.local/pipx/venvs/commitizen/lib/python3.8/site-packages/commitizen/config/json_config.py", line 28, in set_key
    parser = json.load(f)
  File "/usr/lib/python3.8/json/__init__.py", line 293, in load
    return loads(fp.read(),
  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 340, in decode
    raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 2 column 1 (char 12)

Desired behavior

Correctly detected there is already a config file. But I am not sure what should cz init do next. It seems to be a undefined behavior currently.

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