tchar / ulauncher-albert-calculate-anything

A ULauncher/Albert extension that supports currency, units and date time conversion, as well as a calculator that supports complex numbers and functions.
MIT License
103 stars 13 forks source link

[bug] Extension crashed after updating and saving new settings and then crashes instantly on reload #25

Closed darkfishy closed 3 years ago

darkfishy commented 3 years ago

Describe the bug

After updating the extension to the latest version (cdc539c), then trying to change values for Default Cities (added salt lake city for e.g.), it wouldn't save the settings. Now, it crashes on reload.

To Reproduce

Steps to reproduce the behavior:

Expected behavior

Save the settings and be able to run the extension. Now it crashes on reload with following error in ulauncher: ERROR | ulauncher.api.server.ExtensionRunner: _run_process() | Extension "com.github.tchar.ulauncher-albert-calculate-anything" failed with an error: locale.Error: unsupported locale setting

Error in preferences pane when saving (first time)

Message: 'com.github.tchar.ulauncher-albert-calculate-anything' Error Name: UnhandledError Type: KeyError

Stacktrace:

Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/ulauncher/ui/windows/PreferencesUlauncherDialog.py", line 198, in on_scheme_callback
    resp = rt.dispatch(self, scheme_request.get_uri())
  File "/usr/lib/python3.9/site-packages/ulauncher/utils/Router.py", line 49, in dispatch
    return callback(context, url_params)
  File "/usr/lib/python3.9/site-packages/ulauncher/ui/windows/PreferencesUlauncherDialog.py", line 444, in prefs_extension_update_prefs
    controller = ExtensionServer.get_instance().get_controller(ext_id)
  File "/usr/lib/python3.9/site-packages/ulauncher/api/server/ExtensionServer.py", line 76, in get_controller
    return self.controllers[extension_id]
KeyError: 'com.github.tchar.ulauncher-albert-calculate-anything'

Logs

If possible please provide the logs from the log directory

Screenshots

screenshot-2021_08_12-14_00_34+1000

Desktop (please complete the following information)

tchar commented 3 years ago

Hello @darkfishy,

This looks weird it works on my end. First of all I have to assume that in the log directory /home/username/.cache/com.github.tchar.calculate-anything/log you replaced username with your actual username.

This error looks like it comes from setting the locale. Did you by any chance update your system or have misconfigured locales? Try running this

python -c "import locale;locale.setlocale(locale.LC_ALL, 'en_US.UTF-8');print('Ok')"

And tell me it gives you any error

If you get any error, then the source of problem probably comes from the locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') in main

darkfishy commented 3 years ago

Hey @tchar ,

Yes, I did replace the username :-) Though the directory is empty and there aren't any other dotfiles either.

I do get an error with that statement:

% python -V
Python 3.9.6
% python -c "import locale;locale.setlocale(locale.LC_ALL, 'en_US.UTF-8');print('Ok')"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.9/locale.py", line 610, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting
% locale -a
C
en_AU.utf8
POSIX
% locale
LANG=en_AU.UTF-8
LC_CTYPE="en_AU.UTF-8"
LC_NUMERIC="en_AU.UTF-8"
LC_TIME="en_AU.UTF-8"
LC_COLLATE="en_AU.UTF-8"
LC_MONETARY="en_AU.UTF-8"
LC_MESSAGES="en_AU.UTF-8"
LC_PAPER="en_AU.UTF-8"
LC_NAME="en_AU.UTF-8"
LC_ADDRESS="en_AU.UTF-8"
LC_TELEPHONE="en_AU.UTF-8"
LC_MEASUREMENT="en_AU.UTF-8"
LC_IDENTIFICATION="en_AU.UTF-8"
LC_ALL=
% localectl
   System Locale: LANG=en_AU.UTF-8
       VC Keymap: n/a
      X11 Layout: n/a

I reckon your suspicion is correct.

darkfishy commented 3 years ago

Looking at the linked code https://github.com/tchar/ulauncher-albert-calculate-anything/blob/cdc539cc0e886bf19bd6779ef2fe6bbdab6a4e80/main.py#L38 do you reckon it would be worth first checking if user has a locale set already using locale.getlocale() or locale.getdefaultlocale()?

tchar commented 3 years ago

@darkfishy

You are right, it looks like a leftover from the very very begining where I was testing and wanted the results to be consinstent and forgot to remove it. Pfff I look retarded now

I will fix it. thanks for letting me know

In the meantime you can comment out that line, Probably, I will remove it anyways, since I use locale.getLocale() in the code somewhere.

Just keep an eye on the issue to let me know if the future fix works for you.

Cheers

darkfishy commented 3 years ago

All good mate. And I should have also started with thanks for the great effort in this plugin :-)

I'll report back with the effect of changes.

darkfishy commented 3 years ago

Bingo! That worked :-)

tchar commented 3 years ago

@darkfishy try updating the extension, it should be ok now.

darkfishy commented 3 years ago

@tchar confirmed. It is working after updating and reloading. Thanks mate.

tchar commented 3 years ago

Also the logs in the log directory should be there now, they were not created I guess because the program crashed too early.

darkfishy commented 3 years ago

Also the log directory should be there now, it was not created I guess because the program crashed too early.

Ah, that makes sense. I'll check that.

darkfishy commented 3 years ago

And confirmed :)

tchar commented 3 years ago

Great, thanks