cherry-picker icon indicating copy to clipboard operation
cherry-picker copied to clipboard

Bubble up error message

Open dpr-0 opened this issue 1 year ago • 4 comments

Fixes #99

Re: https://github.com/python/cherry-picker/issues/99#issuecomment-1913516938

dpr-0 avatar Jan 28 '24 15:01 dpr-0

Hi @ezio-melotti, thanks for reviewing my PR.

For your questions,

  1. 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
    
  2. and 3.

    The IRC will be raised when validate_sha(self.config["check_sha"]) or self.get_state_and_verify() fail, because both may raise ValueError, so maybe saying f"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?"
    )

dpr-0 avatar Jan 28 '24 16:01 dpr-0

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.

ezio-melotti avatar Jan 28 '24 18:01 ezio-melotti

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.

dpr-0 avatar Jan 29 '24 02:01 dpr-0

@ezio-melotti

dpr-0 avatar Mar 22 '24 06:03 dpr-0