gapan / xdgmenumaker

A command line tool that generates XDG menus for several window managers
GNU General Public License v3.0
56 stars 15 forks source link

UnicodeDecodeError #14

Open Ygarr opened 6 years ago

Ygarr commented 6 years ago
xdgmenumaker -n -i -f jwm

Then got:

<?xml version="1.0"?>
<JWM>
/usr/local/bin/xdgmenumaker:321: GtkWarning: Theme directory 256x256@2/animations of theme hicolor has no size field

  icon = icon_theme.lookup_icon(icon, iconsize, gtk.ICON_LOOKUP_FORCE_SVG)
Traceback (most recent call last):
  File "/usr/local/bin/xdgmenumaker", line 874, in <module>
    main(sys.argv[1:])
  File "/usr/local/bin/xdgmenumaker", line 241, in main
    jwm()
  File "/usr/local/bin/xdgmenumaker", line 768, in jwm
    for menu_category in menu():
  File "/usr/local/bin/xdgmenumaker", line 482, in menu
    entry = get_entry_info(desktopfile, ico_paths=ico_paths)
  File "/usr/local/bin/xdgmenumaker", line 419, in get_entry_info
    command = remove_command_keys(command, desktopfile, icon)
  File "/usr/local/bin/xdgmenumaker", line 358, in remove_command_keys
    command = command.replace('"%k"', desktopfile)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xd1 in position 70: invalid continuation byte
gapan commented 6 years ago

What is the output of the locale command on your system?

There is probably a .desktop file with an invalid character in its filename somewhere in your system.

Ygarr commented 6 years ago

locale LANG=en_US.UTF-8 LC_CTYPE="en_US.UTF-8" LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.UTF-8" LC_COLLATE="en_US.UTF-8" LC_MONETARY="en_US.UTF-8" LC_MESSAGES="en_US.UTF-8" LC_PAPER="en_US.UTF-8" LC_NAME="en_US.UTF-8" LC_ADDRESS="en_US.UTF-8" LC_TELEPHONE="en_US.UTF-8" LC_MEASUREMENT="en_US.UTF-8" LC_IDENTIFICATION="en_US.UTF-8" LC_ALL=

gapan commented 6 years ago

Can you try applying this patch and see if it outputs anything to stderr?

diff --git a/src/xdgmenumaker b/src/xdgmenumaker
index ba5a037..90fe5f0 100755
--- a/src/xdgmenumaker
+++ b/src/xdgmenumaker
@@ -355,9 +355,13 @@ def remove_command_keys(command, desktopfile, icon):
     # location of the desktop file as either a URI (if for example gotten from
     # the vfolder system) or a local filename or empty if no location is
     # known."
-    command = command.replace('"%k"', desktopfile)
-    command = command.replace("'%k'", desktopfile)
-    command = command.replace('%k', desktopfile)
+    try:
+        command = command.replace('"%k"', desktopfile)
+        command = command.replace("'%k'", desktopfile)
+        command = command.replace('%k', desktopfile)
+    except UnicodeDecodeError:
+        print("ERROR: UnicodeDecodeError while reading {}".format(desktopfile),
+                file=sys.stderr)
     # removing any remaining keys from the command. That can potentially remove
     # any other trailing options after the keys,
     command = command.partition('%')[0]