hedyhli / starcli

:sparkles: Browse trending GitHub projects from your command line
https://pypi.org/project/starcli/
MIT License
547 stars 50 forks source link

Bug: Unable to launch starcli on a new machine - cache file missing #122

Closed dzmitry-kankalovich closed 1 year ago

dzmitry-kankalovich commented 1 year ago

I went to install starcli on my personal MBP and ran into following problem:

starcli
Traceback (most recent call last):
  File "/opt/homebrew/bin/starcli", line 8, in <module>
    sys.exit(cli())
  File "/opt/homebrew/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/opt/homebrew/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/opt/homebrew/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/homebrew/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/opt/homebrew/lib/python3.10/site-packages/starcli/__main__.py", line 191, in cli
    with open(CACHED_RESULT_PATH, "a+") as f:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/dkankalovich/.cache/starcli.json'

It seems like some regression happened in latest versions and now starcli expects that cache file to be present.

Python version

3.10

your operating system (and terminal type or shell of needed)

macOS 13.1 (22C65)

starcli version

starcli==2.17.1

reproduce

Delete ~/.cache dir and run starcli.

workaround

Create an empty json file:

mkdir -p /Users/dkankalovich/.cache && echo "{}" > /Users/dkankalovich/.cache/starcli.json
dzmitry-kankalovich commented 1 year ago

The culprit is in __main__.py at line 201:

            with open(CACHED_RESULT_PATH, "a+") as f:

This will fail if ~/.cache directory doesn't exist.