dylanaraps / pywal

🎨 Generate and change color-schemes on the fly.
MIT License
8.22k stars 311 forks source link

After system upgrade: "IndexError: list index out of range" #648

Closed anoduck closed 2 years ago

anoduck commented 2 years ago

After a basic system upgrade, the script that I wrote using pywal to change desktop wallpapers began generating the error list index out of range. Since then, I have tried numerous means to circumvent the generation of this error, primarily attempting to avoid pywal from calling the wallpaper.get() function. Unfortunately, this has not been successful, and the function is executed regardless of how pywal is implemented. Full output is below:

Traceback (most recent call last):
  File "/home/user/walli/walli.py", line 75, in <module>
    main()
  File "/home/user/walli/walli.py", line 68, in main
    set_wall(args)
  File "/home/user/walli/walli.py", line 48, in set_wall
    image = pywal.image.get_random_image(DIR)
  File "/usr/local/lib/python3.9/site-packages/pywal/image.py", line 28, in get_random_image
    images, current_wall = get_image_dir(img_dir)
  File "/usr/local/lib/python3.9/site-packages/pywal/image.py", line 17, in get_image_dir
    current_wall = wallpaper.get()
  File "/usr/local/lib/python3.9/site-packages/pywal/wallpaper.py", line 154, in get
    return util.read_file(current_wall)[0]
IndexError: list index out of range

My script that uses pywal is located at: https://github.com/anoduck/walli

anoduck commented 2 years ago

Although this issue might appear to be similar to #528, it is not. The error persists through reboot AND has persisted through another system update as well. When first encountered, it was assummed that this error would be resolved in the dev branch and a resolution is simply awaiting release. This is not the case, fetching directly from git and building the module did not resolve the issue. It is surprising there was not already an issue report created for this error, and it appears no one else is encountering it.

anoduck commented 2 years ago

Unquestionably, this error is the result of the use of [0] in line 205 of the wallpaper.get function in wallpaper.py. Where [0] does not appear to be defined or is being overwritten in the script.

arcmags commented 2 years ago

So, I tried to trace through your code and find your problem, but it appears the version of walli you have posted on github is not the same version you ran here (there is no image = pywal.image.get_random_image(DIR) in your walli script on github).

Also, the use of [0] is most certainly defined. util.read_file() returns a list, so util.read_file(current_wall)[0] is returning the first item in the list. If there is no first item in the list, then the list must be empty (hence: IndexError: list index out of range). Why would the list be empty? Because the output of wallpaper.get() is an empty list. Why would the output of wallpaper.get() be empty? Maybe you have changed the value of CACHE_DIR, I see a commented out line in walli that is doing this, but because you aren't running the same version of walli that's on your github, I can't help you any further.

anoduck commented 2 years ago

Resolved... ~/.cache/wal/wal was not a valid file. Removed it, and it works.