github-stats icon indicating copy to clipboard operation
github-stats copied to clipboard

Action fails to run

Open pjirsa opened this issue 4 years ago • 5 comments
trafficstars

Github action started failing after no changes to repo or access token. Output below:

Traceback (most recent call last):
  File "generate_images.py", line 61, in generate_languages
    sorted_languages = sorted((await s.languages).items(), reverse=True,
  File "/home/runner/work/github-stats/github-stats/github_stats.py", line 385, in languages
    await self.get_stats()
  File "/home/runner/work/github-stats/github-stats/github_stats.py", line 308, in get_stats
    name = repo.get("nameWithOwner")
AttributeError: 'NoneType' object has no attribute 'get'
Traceback (most recent call last):
  File "generate_images.py", line 108, in <module>
    asyncio.run(main())
  File "/opt/hostedtoolcache/Python/3.8.6/x64/lib/python3.8/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/opt/hostedtoolcache/Python/3.8.6/x64/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "generate_images.py", line 104, in main
    await asyncio.gather(generate_languages(s), generate_overview(s))
  File "generate_images.py", line 36, in generate_overview
    output = re.sub("{{ name }}", await s.name, output)
  File "/home/runner/work/github-stats/github-stats/github_stats.py", line 352, in name
    await self.get_stats()
  File "/home/runner/work/github-stats/github-stats/github_stats.py", line 308, in get_stats
    name = repo.get("nameWithOwner")
AttributeError: 'NoneType' object has no attribute 'get'
Error: Process completed with exit code 1.

pjirsa avatar Nov 24 '20 14:11 pjirsa

Hi, thanks for using the project and taking the time to open this issue! This brief response is to let you know that I've seen this, and will hopefully have time to take a look at this over the weekend.

Without having looked too closely, I am going to guess that this is a somewhat similar issue to #5 and that there is some edge-case return value from the API that my code does not take into account. It might actually be the exact same issue as #5, except in a different API response.

Unfortunately, the error messages from the code are (purposefully) less than helpful, because I want to be somewhat careful not to accidentally leak information about users' private repos in the Actions logs. However, if you clone the repo locally, it should be possible to add helpful print statements that may be able to indicate which repository this is failing on. From there, we can work together to assess the relevant GitHub API response, add an exception handler in the right place, and patch the code so that this doesn't happen for anyone else.

jstrieb avatar Nov 26 '20 03:11 jstrieb

chiming in to report that i also ran into this problem.

here is my error (its at a different line but has the same error as OP)

Run python3 --version
Python 3.8.6
Traceback (most recent call last):
  File "generate_images.py", line 115, in <module>
    asyncio.run(main())
  File "/opt/hostedtoolcache/Python/3.8.6/x64/lib/python3.8/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/opt/hostedtoolcache/Python/3.8.6/x64/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "generate_images.py", line 111, in main
    await asyncio.gather(generate_languages(s), generate_overview(s))
  File "generate_images.py", line 39, in generate_overview
    output = re.sub("{{ contributions }}", f"{await s.total_contributions:,}",
  File "/home/runner/work/sw-yx/sw-yx/github_stats.py", line 429, in total_contributions
    by_year = (await self.queries.query(Queries.all_contribs(years))) \
AttributeError: 'NoneType' object has no attribute 'get'

i'm not ready to debug this myself yet but just wanted to offer my report for someone who might know how to fix this

swyxio avatar Jan 12 '21 19:01 swyxio

Hi @sw-yx and @pjirsa! I really apologize for the long delay on checking this out. As I mentioned in another issue, my semester has started, so I have had to spend more time doing math homework, and less time working on fun side projects. I hope that the delayed response has not caused you to abandon incorporating this project into your GitHub profile READMEs (or wherever else you might be interested in using the generated stats images).

I have done my best to patch the issues where None is being returned in these circumstances, but it is hard to test them for your use-case and be 100% sure that they will work for the type of API responses that are causing the issues. I will leave this issue open for a little while in case more discussion and/or fixes are necessary.

Tangent (feel free to ignore): this application was originally a script I wrote primarily for personal use, so I whipped it up quickly in Python. In hindsight, I really wish I had used a language with stronger typing guarantees because it feels like the vast majority of issues/bugs are these sort of random None bugs where proper case statements, pattern matching, and option/sum types would force me to solve the problems before they even crop up. If I had infinite time, I would probably reimplement this in SML, OCaml, or F#, but at this point that seems pretty unlikely. Instead, I'll have to settle for putting out these fires as they show up. Next time I'll try to be a bit quicker about it, though!

Thanks again to both of you for taking the time to report these issues! I shudder to think how many bugs like this there are that have gone un-reported, and which are causing others to skip over this project in favor of others.

jstrieb avatar Feb 09 '21 06:02 jstrieb

haha what a nice message :) i mean, you dont owe anyone anything so no fear

i would say dont reach for those functional languages so quickly. theres a reason the JS and Pythons of the world rule the roost - Worse is Better. i think learning to work with their typesystems - python has typehints - and write good code is more valuable than going to comparatively niche, if technically superior, languages. just my 2c

swyxio avatar Feb 22 '21 22:02 swyxio