Skip to content

Commit

Permalink
Handle empty command lines - catapult will break if a distribution ha…
Browse files Browse the repository at this point in the history
…s desktop files with empty command-lines (#32)

* Handle empty command lines - catapult will break if a distribution has desktop files with empty command-lines

Example:
```
08:49:12 DEBUG: AppsPlugin: 569 items in index
08:49:12 DEBUG: AppsPlugin: 569 items in index
08:49:16 DEBUG: AppsPlugin: Updating index...
08:49:16 DEBUG: AppsPlugin: 569 items in index
08:49:17 DEBUG: SearchManager: Starting search for 'q'
08:49:17 DEBUG: AppsPlugin: Found qemu.desktop for 'q'
08:49:17 ERROR: Failed to get search results from apps
Traceback (most recent call last):
  File "/tmp/catapult-devel.git/catapult/search.py", line 59, in _get_results
    for i, result in enumerate(plugin.search(query)):
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/catapult-devel.git/catapult/plugins/apps.py", line 99, in search
    description=self._get_description(app),
                ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/catapult-devel.git/catapult/plugins/apps.py", line 61, in _get_description
    description = re.sub(r" %\w\b", "", description)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/re/__init__.py", line 186, in sub
    return _compile(pattern, flags).sub(repl, string, count)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: expected string or bytes-like object, got 'NoneType'
08:49:17 DEBUG: SearchManager: builtins delivered in 0 ms
08:49:17 DEBUG: SearchManager: Found 0 results
08:49:17 DEBUG: SearchManager: Adjusted scores in 0 ms
```

* Move condition to indexing

---------

Co-authored-by: Osmo Salomaa <otsaloma@iki.fi>
  • Loading branch information
UffeJakobsen and otsaloma authored Oct 11, 2024
1 parent bdfad12 commit 8b285ed
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions catapult/plugins/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def launch(self, window, id):
def _list_apps(self):
key = lambda x: x.get_filename().lower()
for app in sorted(Gio.AppInfo.get_all(), key=key):
if not self.conf.ignore_only_show_in:
if not app.should_show(): continue
if not self.conf.ignore_only_show_in and not app.should_show(): continue
if not app.get_commandline(): continue
id = app.get_id()
if id == "io.otsaloma.catapult.desktop": continue
yield id, app
Expand Down

0 comments on commit 8b285ed

Please sign in to comment.