Skip to content

Commit

Permalink
When raising error, show the current state vs expected state (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariatta authored Oct 10, 2023
1 parent e4ece75 commit e4f927d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion cherry_picker/cherry_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,9 @@ def abort_cherry_pick(self):
run `git cherry-pick --abort` and then clean up the branch
"""
if self.initial_state != WORKFLOW_STATES.BACKPORT_PAUSED:
raise ValueError("One can only abort a paused process.")
raise ValueError(
f"One can only abort a paused process. Current state: {self.initial_state}. Expected state: {WORKFLOW_STATES.BACKPORT_PAUSED}"
)

try:
validate_sha("CHERRY_PICK_HEAD")
Expand Down
5 changes: 3 additions & 2 deletions cherry_picker/test_cherry_picker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import pathlib
import re
import subprocess
import warnings
from collections import ChainMap
Expand Down Expand Up @@ -1141,7 +1142,7 @@ def test_continue_cherry_pick_invalid_state(tmp_git_repo_dir):

assert get_state() == WORKFLOW_STATES.UNSET

with pytest.raises(ValueError, match=r"^One can only continue a paused process.$"):
with pytest.raises(ValueError, match=re.compile(r"^One can only continue a paused process.")):
cherry_picker.continue_cherry_pick()

assert get_state() == WORKFLOW_STATES.UNSET # success
Expand All @@ -1167,7 +1168,7 @@ def test_abort_cherry_pick_invalid_state(tmp_git_repo_dir):

assert get_state() == WORKFLOW_STATES.UNSET

with pytest.raises(ValueError, match=r"^One can only abort a paused process.$"):
with pytest.raises(ValueError, match=re.compile(r"^One can only abort a paused process.")):
cherry_picker.abort_cherry_pick()


Expand Down

0 comments on commit e4f927d

Please sign in to comment.