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

[1.0.0] Error "403 rate limit exceeded" crashes watch_gha_runs #8

Closed
hartwork opened this issue Apr 27, 2023 · 8 comments
Closed

[1.0.0] Error "403 rate limit exceeded" crashes watch_gha_runs #8

hartwork opened this issue Apr 27, 2023 · 8 comments

Comments

@hartwork
Copy link

Hi Ned, very nice tool!

I noticed that watch_gha_runs does not handle rate limited errors gracefully yet but just crashes with a backtrace like this:

# watch_gha_runs https://github.com/textualize/textual
Traceback (most recent call last):
  File "/tmp/tmp.j7GbaDXGjF/aptus/venv/bin/watch_gha_runs", line 8, in <module>
    sys.exit(main())
  File "/tmp/tmp.j7GbaDXGjF/aptus/venv/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/tmp/tmp.j7GbaDXGjF/aptus/venv/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/tmp/tmp.j7GbaDXGjF/aptus/venv/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/tmp/tmp.j7GbaDXGjF/aptus/venv/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/tmp/tmp.j7GbaDXGjF/aptus/venv/lib/python3.10/site-packages/watchgha/watch_runs.py", line 149, in main
    doit()
  File "/tmp/tmp.j7GbaDXGjF/aptus/venv/lib/python3.10/site-packages/watchgha/watch_runs.py", line 128, in doit
    done, succeeded = draw_runs(
  File "/tmp/tmp.j7GbaDXGjF/aptus/venv/lib/python3.10/site-packages/watchgha/watch_runs.py", line 179, in draw_runs
    events = trio.run(get_events, url, datafn)
  File "/tmp/tmp.j7GbaDXGjF/aptus/venv/lib/python3.10/site-packages/trio/_core/_run.py", line 2010, in run
    raise runner.main_task_outcome.error
  File "/tmp/tmp.j7GbaDXGjF/aptus/venv/lib/python3.10/site-packages/watchgha/watch_runs.py", line 185, in get_events
    runs = json.loads(await datafn(url))["workflow_runs"]
  File "/tmp/tmp.j7GbaDXGjF/aptus/venv/lib/python3.10/site-packages/watchgha/utils.py", line 77, in get_data
    resp.raise_for_status()
  File "/tmp/tmp.j7GbaDXGjF/aptus/venv/lib/python3.10/site-packages/httpx/_models.py", line 749, in raise_for_status
    raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Client error '403 rate limit exceeded' for url 'https://api.github.com/repos/textualize/textual/actions/runs?per_page=40'
For more information check: https://httpstatuses.com/403

Are there places to wrap this in clean error output?

Best, Sebastian

Repository owner deleted a comment from Ngocchieu98 Jun 24, 2023
@nedbat
Copy link
Owner

nedbat commented Jun 24, 2023

I guess I could show a less cluttered output when the rate limit is hit. You can set a GITHUB_TOKEN environment variable to avoid the limit.

@hartwork
Copy link
Author

With the latest fixes (commit bdc9875) it now dies without a backtrace but also without any error message:

# watch_gha_runs https://github.com/textualize/textual ; echo $?
Focus change doesn't always update `text-style`style main [issues]   ad4308562b5b  @06-28 11:15pm
   ✓ success      FAQ issue comment   view 5405927659
OptionList with only one parameter does not return highlighted main [issues]   ad4308562b5b  @06-28 12:00pm
   ✗ failure      Closed issue comment   view 5399776969
      add-comment                    ✗ failure Did we solve your problem?
1

Is that what you intended?

@nedbat
Copy link
Owner

nedbat commented Jun 29, 2023

Hmm... no. I'll investigate some more. I'm assuming that the request here is, "make the error output nicer," not "retry nicely when I'm rate-limited."

@nedbat nedbat reopened this Jun 29, 2023
@hartwork
Copy link
Author

Hi @nedbat thanks for re-opening! I think some short non-traceback error hinting about GITHUB_TOKEN and/or rate limiting would be perfect. (Reducing the frequency of requests is not what I wanted to suggest, correct.)

@nedbat
Copy link
Owner

nedbat commented Jun 30, 2023

Try main now. I removed the traceback, and added more information that GitHub provides:

% watch_gha_runs
Client error '403 Forbidden' for url 'https://api.github.com/repos/nedbat/coveragepy/actions/runs?per_page=40&branch=nedbat%2Ftest-metacov-kit-nightly'
For more information check: https://httpstatuses.com/403
message: API rate limit exceeded. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)
documentation_url: https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-limiting

@hartwork
Copy link
Author

@nedbat I confirm, thank you!

@nedbat
Copy link
Owner

nedbat commented Jul 3, 2023

This is now released as part of watchgha 2.0.0.

@hartwork
Copy link
Author

hartwork commented Jul 3, 2023

Cool!

Repository owner deleted a comment from Ngocchieu98 Aug 25, 2023
Repository owner deleted a comment from Ngocchieu98 Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants