Bubble up error message
Fixes #99
Re: https://github.com/python/cherry-picker/issues/99#issuecomment-1913516938
Hi @ezio-melotti, thanks for reviewing my PR.
For your questions,
-
The current output looks like this:
$ cherry_picker 🐍 🍒 ⛏ Error validate sha The sha listed in the branch name, 7f777ed95a19224294949e1b4ce56bbffcb1fe9f, is not present in the repository -
and 3.
The IRC will be raised when
validate_sha(self.config["check_sha"])orself.get_state_and_verify()fail, because both may raiseValueError, so maybe sayingf"Cannot locate sha commit or get state. Are you inside a {config['repo']} repo?"?
4 . Yes, the test would be like this (tested):
def test_cli_invoked_invalid_repo():
with pytest.raises(subprocess.CalledProcessError) as exc_info:
subprocess.check_output("cherry_picker")
assert exc_info.value.output.decode().startswith(
"\U0001F40D \U0001F352 \u26CF\nCannot locate sha commit or get state. Are you inside a cpython repo?"
)
Regarding the error message: it looks like the original error message (at least for the invalid sha) is clear enough, so perhaps there is no need to add the f"Cannot locate sha commit or get state. Are you inside a {config['repo']} repo?". Is this true also for the "get state"? (BTW, it's not clear just by reading the proposed message what "get state" is supposed to do, why it failed, and how to fix the problem.)
Regarding the test, there is actually a test already, but only checks the exception type: https://github.com/python/cherry-picker/blob/d7c32647be3060e44c2c1bcece686373a70f1063/cherry_picker/test_cherry_picker.py#L407-L410
You can use pytest.raises to check that the error message mentions the invalid sha and (possibly separately) whatever error message is raised when getting the state fails.
Is this true also for the "get state"?
I think the original error message is clear too:
https://github.com/python/cherry-picker/blob/d7c32647be3060e44c2c1bcece686373a70f1063/cherry_picker/cherry_picker.py#L675-L686
If we both agree there is no need to add the summary of error message, I can just enhance existing tests.
@ezio-melotti