c4urself / bump2version

Version-bump your software with a single command
https://pypi.python.org/pypi/bump2version
MIT License
1.05k stars 134 forks source link

Unhelpful error message is generated when `part` is invalid #195

Open jwodder opened 3 years ago

jwodder commented 3 years ago

If a typo or other mistake is made on the command line and the user tries to run bump2version with an invalid part (e.g., bump2version pathc), the program will not detect that part is invalid. Instead, it ends up making no changes to the repository and then tries to commit anyway, and at that point the user is shown gobs of unhelpful error messages like the following:

Failed to run ['git', 'commit', '-F', '/var/folders/l7/wrkq93d133d8zpn36fmqrq0r0000gn/T/tmproiamvy7']: return code 1, output: b"On branch auto-bumpversion\nYour branch is up to date with 'origin/auto-bumpversion'.\n\nUntracked files:\n\t.env\n\tauto\n\nnothing added to commit but untracked files present\n"
Traceback (most recent call last):
  File "/Users/jwodder/.local/pipx/venvs/bump2version/lib/python3.9/site-packages/bumpversion/vcs.py", line 31, in commit
    subprocess.check_output(
  File "/usr/local/Cellar/python@3.9/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 420, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/usr/local/Cellar/python@3.9/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 524, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['git', 'commit', '-F', '/var/folders/l7/wrkq93d133d8zpn36fmqrq0r0000gn/T/tmproiamvy7']' returned non-zero exit status 1.
Traceback (most recent call last):
  File "/Users/jwodder/.local/bin/bump2version", line 8, in <module>
    sys.exit(main())
  File "/Users/jwodder/.local/pipx/venvs/bump2version/lib/python3.9/site-packages/bumpversion/cli.py", line 135, in main
    context = _commit_to_vcs(files, context, config_file, config_file_exists, vcs,
  File "/Users/jwodder/.local/pipx/venvs/bump2version/lib/python3.9/site-packages/bumpversion/cli.py", line 706, in _commit_to_vcs
    vcs.commit(
  File "/Users/jwodder/.local/pipx/venvs/bump2version/lib/python3.9/site-packages/bumpversion/vcs.py", line 39, in commit
    raise exc
  File "/Users/jwodder/.local/pipx/venvs/bump2version/lib/python3.9/site-packages/bumpversion/vcs.py", line 31, in commit
    subprocess.check_output(
  File "/usr/local/Cellar/python@3.9/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 420, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/usr/local/Cellar/python@3.9/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 524, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['git', 'commit', '-F', '/var/folders/l7/wrkq93d133d8zpn36fmqrq0r0000gn/T/tmproiamvy7']' returned non-zero exit status 1.

bump2version should instead detect invalid parts and error out with a human-friendly message indicating that the part is invalid.

florisla commented 3 years ago

100% agreed!

lowell80 commented 3 years ago

One minor addition: I think it would be helpful to provide a list of valid parts to the user both when (1) they provide an invalid value, and (2) whenever they forget to include part argument altogether.

Speaking as someone who has done both, repeatedly. :-)

lowell80 commented 2 years ago

Is this fixed in #168? I just hit this again on v1.0.1 with a new developer when they typed bumpversion help which caused confusion. Is this just waiting on the next release?

darrincedwards commented 2 years ago

Having the opposite outcome for such a typo; it does make a commit that doesn't change the version, and "mangles" the version number in versioned files: `darrin@cornelia ~/myproject (development)> cat setup.cfg | grep version version = 1.4.0 darrin@cornelia ~/myproject (development)> bumpversion kablooie darrin@cornelia ~/myproject (development)> git log -n 1 commit 727e9ca3d2dbb2291e38132d5da5197b404106a9 (HEAD -> development) Author: Darrin Edwards dedwards@example.com Date: Thu Jun 30 16:51:41 2022 -0500

Bump version: 1.4.0 → 1.4.0

darrin@cornelia ~/myproject (development)> cat setup.cfg | grep version version = version = 1.4.0 ` (note the extra "version =" in the last line)