bilelmoussaoui / Hardcode-Tray

Fixes Hardcoded tray icons in Linux
Other
863 stars 63 forks source link

Crash with UnboundLocalError #763

Open renyhp opened 1 year ago

renyhp commented 1 year ago

Specifications

Issue

hardcode-tray just crashes before doing anything.

$ sudo /usr/bin/hardcode-tray --conversion-tool RSVGConvert --size 22 --theme Papirus --apply
Welcome to Hardcode-Tray!
Hardcode-Tray replaces some icons on the binary files of some applications. 
Please close all the running applications before running Hardcode-Tray script.
Desktop Environment: Xfce
Scaling Factor: 1
Icon Size: 22
Icon Theme: Papirus
Conversion Tool: RSVGConvert
To Do: All
Applying now…

Traceback (most recent call last):
  File "/usr/bin/hardcode-tray", line 123, in <module>
    App.execute()
  File "/usr/lib/python3/dist-packages/HardcodeTray/app.py", line 100, in execute
    apps = App.get_supported_apps()
  File "/usr/lib/python3/dist-packages/HardcodeTray/app.py", line 90, in get_supported_apps
    application_data = Parser(db_file)
  File "/usr/lib/python3/dist-packages/HardcodeTray/modules/parser.py", line 47, in __init__
    self._read()
  File "/usr/lib/python3/dist-packages/HardcodeTray/modules/parser.py", line 91, in _read
    self._parse_paths(data["app_path"], "app_path")
UnboundLocalError: local variable 'data' referenced before assignment

I also tried

$ apt remove --purge hardcode-tray
$ apt install hardcode-tray

but no success anyway.

renyhp commented 1 year ago

From logs, it looks like /usr/share/hardcode-tray/database/android-messages-desktop.electron.json has a problem.

Here is the content in my PC:

// SPDX-FileCopyrightText: © 2020, Alexey Varfolomeev <varlesh@users.noreply.github.com>
//
// SPDX-License-Identifier: GPL-3.0-or-later
{
    "name": "Android Messages Desktop",
    "app_path": [
        "/opt/Android Messages/",
        "/usr/lib/android-messages-desktop"
    ],
    "icons_path": [
        "/opt/Android Messages/resources/",
        "/usr/lib/android-messages-desktop/resources/"
    ],
    "binary": "app.asar",
    "script": "electron",
    "icons": {
        "tray": {
            "original": "resources/tray/icon.png",
            "theme": "android-messages-desktop-tray"
        },
        "tray-unread": {
            "original": "resources/tray/unread_icon.png",
            "theme": "android-messages-desktop-tray-unread"
        }
    }
}

In the python shell,

Type "help", "copyright", "credits" or "license" for more information.
>>> import json
>>> json.load(open('/usr/share/hardcode-tray/database/android-messages-desktop.electron.json'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.10/json/__init__.py", line 293, in load
    return loads(fp.read(),
  File "/usr/lib/python3.10/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.10/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.10/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)

I don't have any idea why it's complaining.

I temporarily patched /usr/lib/python3/dist-packages/HardcodeTray/modules/parser.py by adding a return statement in the except block in Parser._read() (this really looks like something that should be done anyway)

andrewth16 commented 10 months ago

I ran into this, too.

I did a bit more digging. It appears that any .json file in /usr/share/hardcode-tray/database/ that contains inline JSON comments (i.e. android-messages-desktop.electron.json Line 1) will cause the json.load() to fail to load any data in parser.py Line 84 See Stack overflow link.

A easy workaround is to only try to parse the applications you need using the hardcode-tray --only option. If that does not work, you can simply remove the JSON comments from the offending files.

genderneutralnoun commented 5 months ago

I'm getting a similar error even with all the comments removed from the files.

cleer73 commented 1 month ago

@genderneutralnoun I was able to remove all the comments from the JSON files here: /usr/share/hardcode-tray/database/. And I noticed that a couple of those files had a typo of {{ at the top of the file, making the formatting incorrect. I want to say it was the bauh.json and the blueman.electron.json, but I didn't note it as I was editing all the files.

Once all those comments and the errors where removed everything ran great for me.

Unfortunately when I look at the files in this projects repo I don't see any of those errors or comments. My guess is somewhere upstream for this package those comments/formatting are getting added in the packaging process.

Hope that helps others looking to fix this issue.

ijash commented 1 week ago

is this https://github.com/bilelmoussaoui/Hardcode-Tray/issues/777 a duplicate?