jstrieb/github-stats

Generate images error

bconnorwhite opened this issue · 8 comments

Getting this error:

Run python3 --version
Python 3.8.5
Traceback (most recent call last):
  File "generate_images.py", line 105, in <module>
    asyncio.run(main())
  File "/opt/hostedtoolcache/Python/3.8.5/x64/lib/python3.8/asyncio/runners.py", line 43, in run
    return loop.run_until_complete(main)
  File "/opt/hostedtoolcache/Python/3.8.5/x64/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "generate_images.py", line 101, in main
    await asyncio.gather(generate_languages(s), generate_overview(s))
  File "generate_images.py", line 41, in generate_overview
    changed = (await s.lines_changed)[0] + (await s.lines_changed)[1]
  File "/home/runner/work/github-stats/github-stats/github_stats.py", line 435, in lines_changed
    r = await self.queries.query_rest(f"/repos/{repo}/stats/contributors")
  File "/home/runner/work/github-stats/github-stats/github_stats.py", line 93, in query_rest
    return r.json()
  File "/opt/hostedtoolcache/Python/3.8.5/x64/lib/python3.8/site-packages/requests/models.py", line 898, in json
    return complexjson.loads(self.text, **kwargs)
  File "/opt/hostedtoolcache/Python/3.8.5/x64/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/opt/hostedtoolcache/Python/3.8.5/x64/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/opt/hostedtoolcache/Python/3.8.5/x64/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
##[error]Process completed with exit code 1.

Hi, unfortunately, I'm not able to replicate this error. Can you provide any additional information about when this took place?

Also, apologies for the late reply. Thanks for using this project!

Looks like the json decode error has been fixed, now I'm getting endless A path returned 202. Retrying... in Generating images. Here's my fork: https://github.com/bconnorwhite/github-stats

Looks like the same as #3

Thanks for mentioning this, those are definitely the same issue.

The problem is probably the GitHub statistics API. For more information see this note in the API docs. To summarize that documentation: the API takes a long time to assemble some repo statistics, and doesn't know how long this operation will take, so it just indefinitely returns 202s unless a repo has cached statistics. If there are lots of repos with complex statistics that aren't cached, it will take a very long time (as you have seen first-hand), even with 10 asynchronous connections. I'm not totally sure why this originally eventually failed with an error, but I don't actually think the error is the heart of the problem – I think working around the limitations of the API with regards to timing will and avoid the complicated issue of replicating the code failure directly.

That being said, I've been meaning to push a workaround to this, but have been way too busy for the last little while. I think adding a timeout would be beneficial, even though it would mean that the resulting traffic statistics would be incomplete.

Didn't mean to close this. Apparently putting "Fix #2" in the commit message auto-closes an issue.

I just pushed something I hope will fix the issue, but I am not totally sure. To be precise: I changed the infinite loop that generates all of the 202s into a loop with a max number of tries that returns incomplete data as a fallback. Please merge the change into your fork and see if it works better.

I pushed some fixes that seem to have resolved #3. Please merge the fixes, and if it works for you, I will close this issue.

Awesome, looks like that worked

I am also getting this error/warning message:

A path returned 202. Retrying...

However the action does not fail, should I be worried?

@yooksi this is normal, and is part of GitHub's API response related to caching. It shouldn't significantly impact the output statistics, nor should it cause any fatal errors in the workflow.