Skip to content

Better error message when cherry-picker repo state is invalid - #147

Closed
potiuk wants to merge 2 commits into
python:mainfrom
potiuk:better-error-message-in-case-of-invalid-state
Closed

Better error message when cherry-picker repo state is invalid#147
potiuk wants to merge 2 commits into
python:mainfrom
potiuk:better-error-message-in-case-of-invalid-state

Conversation

@potiuk

@potiukpotiuk commented Nov 17, 2024

Copy link
Copy Markdown
Contributor

When I played with cherry-picker as we introduced it in Airflow, I manage to set the repo to the state where I always got the message "You're not inside a airflow repo right now!"

After short debugging it turned out that it is because I manage to Ctrl-C and mix git cherry-pick --abort with cherry_picker commands - when I learned how to use it, I did not know that I had to only use cherry-picker --continue command rather than git commands.

This might happen to others, so I think we should have a better way to handle this case.

When this happens you get this exception:

Traceback (most recent call last):
File "/Users/jarek/IdeaProjects/cherry-picker/cherry_picker/cherry_picker.py", line 666, in check_repoself.get_state_and_verify()
File "/Users/jarek/IdeaProjects/cherry-picker/cherry_picker/cherry_picker.py", line 684, in get_state_and_verifyraiseValueError(
ValueError: Run state cherry-picker.state=BACKPORT_LOOP_START in Git config is not known.
Perhaps it has been set by a newer version of cherry-picker. Try upgrading.
Valid states are: BACKPORT_PAUSED, UNSET. If this looks suspicious, raise an issue at https://github.com/python/cherry-picker/issues/new.
As the last resort you can reset the runtime state stored in Git config using the following command: `git config --local --remove-section cherry-picker`
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/jarek/.local/bin/cherry_picker", line 8, in <module>
sys.exit(cherry_pick_cli())
^^^^^^^^^^^^^^^^^
File "/Users/jarek/.local/share/uv/tools/cherry-picker/lib/python3.12/site-packages/click/core.py", line 1157, in __call__returnself.main(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/jarek/.local/share/uv/tools/cherry-picker/lib/python3.12/site-packages/click/core.py", line 1078, in main
rv =self.invoke(ctx)
^^^^^^^^^^^^^^^^
File "/Users/jarek/.local/share/uv/tools/cherry-picker/lib/python3.12/site-packages/click/core.py", line 1434, in invokereturn ctx.invoke(self.callback, **ctx.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/jarek/.local/share/uv/tools/cherry-picker/lib/python3.12/site-packages/click/core.py", line 783, in invokereturn __callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/jarek/.local/share/uv/tools/cherry-picker/lib/python3.12/site-packages/click/decorators.py", line 33, in new_funcreturn f(get_current_context(), *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/jarek/IdeaProjects/cherry-picker/cherry_picker/cherry_picker.py", line 804, in cherry_pick_cli
cherry_picker = CherryPicker(
^^^^^^^^^^^^^
File "/Users/jarek/IdeaProjects/cherry-picker/cherry_picker/cherry_picker.py", line 123, in __init__self.check_repo() # may raise InvalidRepoException^^^^^^^^^^^^^^^^^
File "/Users/jarek/IdeaProjects/cherry-picker/cherry_picker/cherry_picker.py", line 668, in check_reporaise InvalidRepoException(ve.args[0])
cherry_picker.cherry_picker.InvalidRepoException: Run state cherry-picker.state=BACKPORT_LOOP_START in Git config is not known.
Perhaps it has been set by a newer version of cherry-picker. Try upgrading.
Valid states are: BACKPORT_PAUSED, UNSET. If this looks suspicious, raise an issue at https://github.com/python/cherry-picker/issues/new.
As the last resort you can reset the runtime state stored in Git config using the following command: `git config --local --remove-section cherry-picker`

So this PR checks for presence of that message in the exception and it will provide better explanation, and guidance in this case.

Fixes: #99

@ghost

ghost commented Nov 17, 2024

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.
CLA signed

@potiuk
potiukforce-pushed the better-error-message-in-case-of-invalid-state branch from 938ee33 to 7032c27CompareNovember 17, 2024 18:05
@potiuk

Copy link
Copy Markdown
ContributorAuthor

All commit authors signed the Contributor License Agreement.

Signed :)

@potiuk

Copy link
Copy Markdown
ContributorAuthor

Ah .. I noticed I am not the first one #119 -> so I will let maintainers to decide if that is worth fixing (well there are already two of us thinking there is (@serhiy-storchaka ) and choose the righ fix.

@potiuk
potiukforce-pushed the better-error-message-in-case-of-invalid-state branch from 7032c27 to e9b83a5CompareNovember 17, 2024 18:13
@hugovk

Copy link
Copy Markdown
Member

And there is also PR #112.

Comment threaduv.lock Outdated
potiuk added a commit to potiuk/cherry-picker that referenced this pull request Nov 17, 2024
When proposing python#147 I noticed that mypy failed with missing
`types-request` - and while the mypy configuration had
the `--install-types`, it did not work automatically for requests.
The error was:
```
cherry_picker/cherry_picker.py:15: error: Library stubs not installed for
"requests" [import-untyped]
import requests
^
cherry_picker/cherry_picker.py:15: note: Hint: "python3 -m pip install types-requests"
cherry_picker/cherry_picker.py:15: note: (or run "mypy --install-types" to install all missing stub packages)
cherry_picker/cherry_picker.py:15: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
```
I looked a bit closer and noticed the advice from
https://github.com/pre-commit/mirrors-mypy
> Note that using the --install-types is problematic. Mutating the
pre-commit environment at runtime breaks cache and will break parallel
builds.
This PR fixes the problem by removing `--install-types` and installing
types-requests explicitly as additional-dependencies.
starting
@potiukpotiuk mentioned this pull request Nov 17, 2024
potiuk added a commit to potiuk/cherry-picker that referenced this pull request Nov 17, 2024
When somoene uses `uv` to manage their venv, uv.lock is generated
automatically when `uv sync` is run. This PR removes it, so that
it is not committed accidentally (happened in python#147)
@potiukpotiuk mentioned this pull request Nov 17, 2024
When I played with cherry-picker as we introduced it in Airflow,
I manage to set the repo to the state where I always got the
message "You're not inside a airflow repo right now!"
After short debugging it turned out that it is because I manage
to Ctrl-C and mix `git cherry-pick --abort` with `cherry_picker`
commands - when I learned how to use it, I did not know that I
had to only use `cherry-picker --continue` command rather than
git commands.
This might happen to others, so I think we should have a better
way to handle this case.
When this happens you get this exception:
```
Traceback (most recent call last):
File "/Users/jarek/IdeaProjects/cherry-picker/cherry_picker/cherry_picker.py", line 666, in check_repo
self.get_state_and_verify()
File "/Users/jarek/IdeaProjects/cherry-picker/cherry_picker/cherry_picker.py", line 684, in get_state_and_verify
raise ValueError(
ValueError: Run state cherry-picker.state=BACKPORT_LOOP_START in Git config is not known.
Perhaps it has been set by a newer version of cherry-picker. Try upgrading.
Valid states are: BACKPORT_PAUSED, UNSET. If this looks suspicious, raise an issue at https://github.com/python/cherry-picker/issues/new.
As the last resort you can reset the runtime state stored in Git config using the following command: `git config --local --remove-section cherry-picker`
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/jarek/.local/bin/cherry_picker", line 8, in <module>
sys.exit(cherry_pick_cli())
^^^^^^^^^^^^^^^^^
File "/Users/jarek/.local/share/uv/tools/cherry-picker/lib/python3.12/site-packages/click/core.py", line 1157, in __call__
return self.main(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/jarek/.local/share/uv/tools/cherry-picker/lib/python3.12/site-packages/click/core.py", line 1078, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File "/Users/jarek/.local/share/uv/tools/cherry-picker/lib/python3.12/site-packages/click/core.py", line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/jarek/.local/share/uv/tools/cherry-picker/lib/python3.12/site-packages/click/core.py", line 783, in invoke
return __callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/jarek/.local/share/uv/tools/cherry-picker/lib/python3.12/site-packages/click/decorators.py", line 33, in new_func
return f(get_current_context(), *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/jarek/IdeaProjects/cherry-picker/cherry_picker/cherry_picker.py", line 804, in cherry_pick_cli
cherry_picker = CherryPicker(
^^^^^^^^^^^^^
File "/Users/jarek/IdeaProjects/cherry-picker/cherry_picker/cherry_picker.py", line 123, in __init__
self.check_repo() # may raise InvalidRepoException
^^^^^^^^^^^^^^^^^
File "/Users/jarek/IdeaProjects/cherry-picker/cherry_picker/cherry_picker.py", line 668, in check_repo
raise InvalidRepoException(ve.args[0])
cherry_picker.cherry_picker.InvalidRepoException: Run state cherry-picker.state=BACKPORT_LOOP_START in Git config is not known.
Perhaps it has been set by a newer version of cherry-picker. Try upgrading.
Valid states are: BACKPORT_PAUSED, UNSET. If this looks suspicious, raise an issue at https://github.com/python/cherry-picker/issues/new.
As the last resort you can reset the runtime state stored in Git config using the following command: `git config --local --remove-section cherry-picker`
```
So this PR checks for presence of that message in the exception
and it will provide better explanation, and guidance in this case.
Fixes: python#99
@potiuk
potiukforce-pushed the better-error-message-in-case-of-invalid-state branch from e9b83a5 to 0d86d1bCompareNovember 17, 2024 18:26
@potiuk

Copy link
Copy Markdown
ContributorAuthor

And there is also PR #112.

So you have to choose which is the best approach .. But clearly the need is there :)

@potiuk

Copy link
Copy Markdown
ContributorAuthor

Looks green :)

@potiuk

Copy link
Copy Markdown
ContributorAuthor

Any chance to get that improvement in :) (Friendly ping :D)

@potiukpotiuk closed this Dec 13, 2024
@potiukpotiuk reopened this Dec 13, 2024
@ambv

ambv commented Jan 15, 2025

Copy link
Copy Markdown
Contributor

I went with #112 instead.

@ambvambv closed this Jan 15, 2025
@potiuk

Copy link
Copy Markdown
ContributorAuthor

Nice

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"You're not inside a cpython repo right now! 🙅" says cherry_picker when I'm in my cpython git repo

3 participants

@potiuk@hugovk@ambv