Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error message when cherry_picker is called in wrong state #119

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[flake8]
extend-ignore = C408,E203,F841,W503
max-complexity = 10
max-complexity = 12
max-line-length = 88
22 changes: 17 additions & 5 deletions cherry_picker/cherry_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,12 @@

click.echo("\U0001F40D \U0001F352 \u26CF")

chosen_config_path, config = load_config(config_path)

try:
chosen_config_path, config = load_config(config_path)
except ValueError as exc:
click.echo("You're not inside a Git tree right now! \U0001F645", err=True)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this ValueError is expected to be raised by get_sha1_from when executing a git command and an error occurs. But the error may not be caused by the fact that the pwd is not in a git tree; it could be some other errors, like git not being installed.

I suggest just echoing some words like "Got an error when executing git command," and echoing the stderr output from the git command.

click.echo(exc, err=True)
sys.exit(-1)
try:
cherry_picker = CherryPicker(
pr_remote,
Expand All @@ -808,8 +812,11 @@
config=config,
chosen_config_path=chosen_config_path,
)
except InvalidRepoException:
click.echo(f"You're not inside a {config['repo']} repo right now! \U0001F645")
except InvalidRepoException as exc:
click.echo(
f"You're not inside a {config['repo']} repo right now! \U0001F645", err=True
)
click.echo(exc, err=True)
sys.exit(-1)
except ValueError as exc:
ctx.fail(exc)
Expand Down Expand Up @@ -994,7 +1001,12 @@
def get_sha1_from(commitish):
"""Turn 'commitish' into its sha1 hash."""
cmd = ["git", "rev-parse", commitish]
return subprocess.check_output(cmd).strip().decode("utf-8")
try:
return (
subprocess.check_output(cmd, stderr=subprocess.PIPE).strip().decode("utf-8")
)
except subprocess.CalledProcessError as exc:
raise ValueError(exc.stderr.strip().decode("utf-8"))

Check warning on line 1009 in cherry_picker/cherry_picker.py

View check run for this annotation

Codecov / codecov/patch

cherry_picker/cherry_picker.py#L1008-L1009

Added lines #L1008 - L1009 were not covered by tests


def reset_stored_config_ref():
Expand Down
Loading