Repository: espanso/espanso (language: rust)

Issue:
Unexpected exit code from worker 90 on Wayland
Now espanso was finally working fine on Wayland, but as of yesterday it stopped working. :/

`espanso start` appears to start espanso, but the replacements aren't working. And if I execute `espanso restart`, it says that espanso wasn't running, but it also doesn't start it.

`#acfg#` and `#pacfg#` aren't working either, but the log does say that it quit with an unexpected exit code.

```
& thefish @ hx90 in ~/fromsvngit/espanso (master ✔) 0 [11:32:36]
~ espanso log
11:32:38 [daemon(673798)] [INFO] reading configs from: "/home/thefish/.config/espanso"
11:32:38 [daemon(673798)] [INFO] reading packages from: "/home/thefish/.config/espanso/match/packages"
11:32:38 [daemon(673798)] [INFO] using runtime dir: "/home/thefish/.local/share/espanso"
11:32:38 [daemon(673798)] [WARN] keyboard layout watcher couldn't determine active layout.
11:32:38 [daemon(673798)] [INFO] watching for changes in path: "/home/thefish/.config/espanso"
11:32:38 [daemon(673798)] [INFO] espanso version: 2.1.5-beta
11:32:38 [daemon(673798)] [INFO] spawning the worker process...
11:32:38 [daemon(673798)] [INFO] binded to IPC unix socket: /home/thefish/.local/share/espanso/espansodaemonv2.sock
11:32:38 [worker(673804)] [INFO] reading configs from: "/home/thefish/.config/espanso"
11:32:38 [worker(673804)] [INFO] reading packages from: "/home/thefish/.config/espanso/match/packages"
11:32:38 [worker(673804)] [INFO] using runtime dir: "/home/thefish/.local/share/espanso"
11:32:38 [worker(673804)] [INFO] binded to IPC unix socket: /home/thefish/.local/share/espanso/espansoworkerv2.sock
11:32:38 [worker(673804)] [INFO] monitoring the status of the daemon process
11:32:38 [worker(673804)] [INFO] using WaylandAppInfoProvider
11:32:38 [worker(673804)] [INFO] detection module will use this keyboard layout: [R=evdev, M=pc86, L=us, V=dvorak-intl, O=terminate:ctrl_alt_bksp]
11:32:38 [worker(673804)] [INFO] using EVDEVSource
11:32:38 [worker(673804)] [INFO] Querying modifier status...
11:32:39 [daemon(673798)] [ERROR] received unexpected exit code from worker 90, exiting

& thefish @ hx90 in ~/fromsvngit/espanso (master ✔) 0 [11:32:41]
~
```

OS: Arch Linux
KDE: 5.24
Espanso version: latest git master

The matches file isn't corrupt and I didn't even edit it in the past few weeks.

How can we further investigate this?
package install fails on debian trixie
**Logs**

```
The following packages have unmet dependencies:
 espanso-wayland : Depends: libwxgtk3.0-gtk3-0v5 but it is not installable
                   Depends: libwxgtk3.0-gtk3-0v5 (>= 3.0.4+dfsg) but it is not installable
                   Depends: libwxbase3.0-0v5 (>= 3.0.4+dfsg) but it is not installable
E: Unable to correct problems, you have held broken packages.
```

**Setup information**
- OS: What OS are you using? debian trixie (testing)
- Version: which version of Espanso are you running? attempting to install 2.1.8

**Analysis**

the issue is that debian does not have these versions of wx any longer:

```
$ apt search '^libwx(base|gtk3)'
Sorting... Done
Full Text Search... Done
libwxbase3.2-1/testing,unstable,now 3.2.2+dfsg-2 amd64 [installed,automatic]
  wxBase library (runtime) - non-GUI support classes of wxWidgets toolkit

libwxgtk3.2-1/testing,unstable,now 3.2.2+dfsg-2 amd64 [installed,automatic]
  wxWidgets Cross-platform C++ GUI toolkit (GTK 3 runtime)

libwxgtk3.2-dev/testing,unstable,now 3.2.2+dfsg-2 amd64 [installed,automatic]
  wxWidgets Cross-platform C++ GUI toolkit (GTK 3 development)
```

however, this seems to be more than simply a packaging issue. when i extract the deb and manually execute the binary, it fails because it is linked to `libwx_gtk3u_html-3.0.so` which doesn't exist on my system. i'm not sure if there were breaking APi changes between these versions of libgtk.


Discussion / hints:
Hey @Vistaus,

I'm sorry you experienced this problem! Could you please try running the following and post the output here?

```
espanso -vvv worker
```

Cheers :)

Hey Frederico! :)

That command produced some more output:

```
& thefish @ hx90 in ~/Downloads 0 [20:20:12]
~ espanso -vvv worker
22:34:07 [worker(838091)] [DEBUG] (1) espanso_path: detected config directory in $HOME/.config/espanso
22:34:07 [worker(838091)] [DEBUG] (1) espanso_path: detected legacy runtime dir: "/home/thefish/.local/share/espanso"
22:34:07 [worker(838091)] [DEBUG] (1) espanso_path: detected default packages dir: "/home/thefish/.config/espanso/match/packages"
22:34:07 [worker(838091)] [INFO] reading configs from: "/home/thefish/.config/espanso"
22:34:07 [worker(838091)] [INFO] reading packages from: "/home/thefish/.config/espanso/match/packages"
22:34:07 [worker(838091)] [INFO] using runtime dir: "/home/thefish/.local/share/espanso"
22:34:07 [worker(838091)] [DEBUG] (1) espanso_config::config::store: loaded default config at path: "/home/thefish/.config/espanso/config/default.yml"
22:34:07 [worker(838091)] [DEBUG] (1) espanso_config::config::store: loaded config at path: "/home/thefish/.config/espanso/config/firefox.yml"
22:34:07 [worker(838091)] [DEBUG] (1) espanso::patch::config_store: skipping 'alacritty_terminal_x11' patch
22:34:07 [worker(838091)] [DEBUG] (1) espanso::patch::config_store: skipping 'emacs_x11' patch
22:34:07 [worker(838091)] [DEBUG] (1) espanso::patch::config_store: skipping 'gedit_x11' patch
22:34:07 [worker(838091)] [DEBUG] (1) espanso::patch::config_store: skipping 'generic_terminal_x11' patch
22:34:07 [worker(838091)] [DEBUG] (1) espanso::patch::config_store: skipping 'kitty_terminal_x11' patch
22:34:07 [worker(838091)] [DEBUG] (1) espanso::patch::config_store: skipping 'konsole_terminal_x11' patch
22:34:07 [worker(838091)] [DEBUG] (1) espanso::patch::config_store: skipping 'libreoffice_writer_x11' patch
22:34:07 [worker(838091)] [DEBUG] (1) espanso::patch::config_store: skipping 'simple_terminal_x11' patch
22:34:07 [worker(838091)] [DEBUG] (1) espanso::patch::config_store: skipping 'simple_terminal_2_x11' patch
22:34:07 [worker(838091)] [DEBUG] (1) espanso::patch::config_store: skipping 'terminator_terminal_x11' patch
22:34:07 [worker(838091)] [DEBUG] (1) espanso::patch::config_store: skipping 'termite_terminal_x11' patch
22:34:07 [worker(838091)] [DEBUG] (1) espanso::patch::config_store: skipping 'thunderbird_x11' patch
22:34:07 [worker(838091)] [DEBUG] (1) espanso::patch::config_store: skipping 'tilix_terminal_x11' patch
22:34:07 [worker(838091)] [DEBUG] (1) espanso::patch::config_store: skipping 'urxvt_terminal_x11' patch
22:34:07 [worker(838091)] [DEBUG] (1) espanso::patch::config_store: skipping 'xterm_terminal_x11' patch
22:34:07 [worker(838091)] [DEBUG] (1) espanso::patch::config_store: skipping 'yakuake_terminal_x11' patch
22:34:07 [worker(838091)] [DEBUG] (1) espanso::patch::config_store: skipping 'virtualbox_x11' patch
22:34:07 [worker(838091)] [DEBUG] (1) espanso::cli::worker: starting with start-reason = None
22:34:07 [worker(838091)] [DEBUG] (1) espanso::icon: skipping extraction for '"/home/thefish/.local/share/espanso/iconv2.png"', as it's already present
22:34:07 [worker(838091)] [DEBUG] (1) espanso::icon: skipping extraction for '"/home/thefish/.local/share/espanso/search.png"', as it's already present
22:34:07 [worker(838091)] [DEBUG] (1) espanso::icon: skipping extraction for '"/home/thefish/.local/share/espanso/icon_no_background.png"', as it's already present
22:34:07 [worker(838091)] [INFO] binded to IPC unix socket: /home/thefish/.local/share/espanso/espansoworkerv2.sock
22:34:07 [worker(838091)] [INFO] using WaylandAppInfoProvider
22:34:07 [worker(838091)] [DEBUG] (2) espanso::cli::worker::engine: using linux capabilities to grant permissions needed by EVDEV backend
22:34:07 [worker(838091)] [DEBUG] (2) espanso::cli::worker::engine: successfully granted permissions using capabilities
22:34:07 [worker(838091)] [INFO] detection module will use this keyboard layout: [R=evdev, M=pc104, L=us, V=dvorak-intl, O=]
22:34:07 [worker(838091)] [INFO] using EVDEVSource
22:34:07 [worker(838091)] [INFO] Querying modifier status...
[wayland-client error] Attempted to dispatch unknown opcode 0 for wl_shm, aborting.
fish: Job 1, 'espanso -vvv worker' terminated by signal SIGABRT (Abort)

& thefish @ hx90 in ~/Downloads 0 [22:34:08]
~
```
@Vistaus Thanks! That's interesting. Did you make some changes with your Desktop Environment? It seems something is wrong with the wayland protocol exchange
@federico-terzi No, I'm still using the same KDE Plasma that I was using before.
@Vistaus Interesting, I don't have many ideas at the moment but I'll definitely investigate :)
@federico-terzi That'd be great. Thank you for looking into it! :)
I missed Espanso too much, so I couldn't wait for this to be solved. So I switched to openSUSE Tumbleweed, eventually got Espanso to compile and now it's working again. So I'll close this issue. :)
It's back again after the Plasma 5.25 update on openSUSE Tumbleweed today. espanso can't be started anymore because of this issue... :(
The output of espanso -vvv worker is the same as above.
I hope this can be fixed. I really miss Espanso (esp. when using it for work). :(
I can reproduce this issue. 
```
❯ ./target/release/espanso daemon                                                                              at  19:25:03
19:25:03 [daemon(73121)] [INFO] reading configs from: "/home/ss/.config/espanso"
19:25:03 [daemon(73121)] [INFO] reading packages from: "/home/ss/.config/espanso/match/packages"
19:25:03 [daemon(73121)] [INFO] using runtime dir: "/home/ss/.cache/espanso"
19:25:03 [daemon(73121)] [INFO] system info: Fedora Linux v36 - kernel: 5.18.13-200.fc36.x86_64
19:25:03 [daemon(73121)] [INFO] watching for changes in path: "/home/ss/.config/espanso"
19:25:03 [daemon(73121)] [INFO] espanso version: 2.1.7-beta
19:25:03 [daemon(73121)] [INFO] spawning the worker process...
19:25:03 [daemon(73121)] [INFO] binded to IPC unix socket: /home/ss/.cache/espanso/espansodaemonv2.sock
19:25:03 [worker(73128)] [INFO] reading configs from: "/home/ss/.config/espanso"
19:25:03 [worker(73128)] [INFO] reading packages from: "/home/ss/.config/espanso/match/packages"
19:25:03 [worker(73128)] [INFO] using runtime dir: "/home/ss/.cache/espanso"
19:25:03 [worker(73128)] [INFO] system info: Fedora Linux v36 - kernel: 5.18.13-200.fc36.x86_64
19:25:03 [worker(73128)] [INFO] using WaylandAppInfoProvider
19:25:03 [worker(73128)] [INFO] binded to IPC unix socket: /home/ss/.cache/espanso/espansoworkerv2.sock
19:25:03 [worker(73128)] [WARN] this version of espanso doesn't come with modulo support, so graphical features (such as Forms and Search) might not be available
19:25:03 [worker(73128)] [WARN] EVDEV backend is being used, but without enabling linux capabilities.
19:25:03 [worker(73128)] [WARN]   Although you CAN run espanso EVDEV backend as root, it's not recommended due
19:25:03 [worker(73128)] [WARN]   to security reasons. Espanso supports linux capabilities to limit the attack surface
19:25:03 [worker(73128)] [INFO] monitoring the status of the daemon process
19:25:03 [worker(73128)] [WARN]   area by only leveraging on the CAP_DAC_OVERRIDE capability (needed to work with
19:25:03 [worker(73128)] [WARN]   /dev/input/* devices to detect and inject text) and disabling it as soon as the
19:25:03 [worker(73128)] [WARN]   initial setup is completed.
19:25:03 [worker(73128)] [INFO] detection module will use this keyboard layout: [R=, M=, L=us, V=, O=]
19:25:03 [worker(73128)] [INFO] using EVDEVSource
19:25:03 [worker(73128)] [INFO] Querying modifier status...
[wayland-client error] Attempted to dispatch unknown opcode 0 for wl_shm, aborting.
19:25:03 [daemon(73121)] [ERROR] received unexpected exit code from worker 90, exiting

```
KDE Plasma again, on Fedora Kinoite. 
Same problem under Archlinux with KDE 5.97.0 / Plasma 5.25.4 (plasma wayland session)
Please check if you have installed wl-clipboard?  At one point there was an overlooked or not-mentioned dependency for this. At one time, I believe I was getting a "worker 90" type of error. My logs:

$ espanso stop
$ espanso daemon
 21:56:15 [daemon(12924)] [INFO] reading configs from: "/home/ykill/.config/espanso"
 21:56:15 [daemon(12924)] [INFO] reading packages from: "/home/ykill/.config/espanso/match/packages"
 21:56:15 [daemon(12924)] [INFO] using runtime dir: "/home/ykill/.cache/espanso"
 21:56:15 [daemon(12924)] [INFO] system info: openSUSE Tumbleweed v20220925 - kernel: 5.19.10-1-default
 21:56:15 [daemon(12924)] [INFO] espanso version: 2.1.7-beta
 21:56:15 [daemon(12924)] [INFO] spawning the worker process...
 21:56:15 [daemon(12924)] [INFO] watching for changes in path: "/home/ykill/.config/espanso"
 21:56:15 [daemon(12924)] [INFO] binded to IPC unix socket: /home/ykill/.cache/espanso/espansodaemonv2.sock
 21:56:15 [daemon(12924)] [WARN] keyboard layout watcher couldn't determine active layout.
 21:56:15 [worker(12931)] [INFO] reading configs from: "/home/ykill/.config/espanso"
 21:56:15 [worker(12931)] [INFO] reading packages from: "/home/ykill/.config/espanso/match/packages"
 21:56:15 [worker(12931)] [INFO] using runtime dir: "/home/ykill/.cache/espanso"
 21:56:15 [worker(12931)] [INFO] system info: openSUSE Tumbleweed v20220925 - kernel: 5.19.10-1-default
 21:56:15 [worker(12931)] [INFO] binded to IPC unix socket: /home/ykill/.cache/espanso/espansoworkerv2.sock
 21:56:15 [worker(12931)] [INFO] using WaylandAppInfoProvider
 21:56:15 [worker(12931)] [INFO] monitoring the status of the daemon process
 21:56:15 [worker(12931)] [INFO] detection module will use this keyboard layout: [R=, M=, L=us, V=, O=]
 21:56:15 [worker(12931)] [INFO] using EVDEVSource
 21:56:16 [worker(12931)] [INFO] Querying modifier status...
 21:56:16 [worker(12931)] [INFO] inject module will use this keyboard layout: [R=, M=, L=us, V=, O=]
 21:56:16 [worker(12931)] [INFO] using EVDEVInjector
 21:56:16 [worker(12931)] [INFO] using WaylandFallbackClipboard

At this point, I can test, and espanso is working. I don't see any further log messages. Please excuse my formatting at this time.

I originally had used a AppImage for espanso, however I now compile from source.

I added: 
wl-clipboard-2.1.0-1.4.x86_64

My setup:
openSUSE TW current
gnome-session-wayland-43
xwayland-22.1.3-1.2


@ykill wl-clipboard is installed for me, however, it's still not working on my openSUSE TW install.
I have the same issue on Arch with KDE 5.26.2. I tried going back to the 2.1.5 beta and it still didn't work. I'm going to try going back further, but perhaps this line from the `espanso -vvv worker` output is helpful (seems like everyone above has the same error):

`[wayland-client error] Attempted to dispatch unknown opcode 0 for wl_shm, aborting.`

I'll report back if I have any success with older versions of espanso.

**Update**: I just went back and tried a few versions all the way back to espanso 2.0.3-alpha and none of them worked, so this may be an issue with a recent KDE update, because I'm quite certain I used that version on KDE Wayland about a year ago. Not sure if this is something that needs to be fixed in espanso or in KDE. 

For now it's quite unfortunate and it's making me choose between espanso and KDE.

**Update 2**: I switched to the LTS kernel (5.15.75) just in case that had any effect and that didn't help either.
I was able to fix this by updating smithay-client-toolkit (sctk) to version 0.15.4. I've submitted a PR, but before that gets merged you can fix this by building espanso from source:

1. Edit `espanso/espanso-detect/Cargo.toml`
2. In the line `sctk = { package = "smithay-client-toolkit", version = "0.14.0", optional = true }` change the version to `0.15.4`.
3. Save the changes and build espanso as normal. It should now work perfectly on KDE Plasma with Wayland.
> I was able to fix this by updating smithay-client-toolkit (sctk) to version 0.15.4. I've submitted a PR, but before that gets merged you can fix this by building espanso from source:
> 
> 1. Edit `espanso/espanso-detect/Cargo.toml`
> 2. In the line `sctk = { package = "smithay-client-toolkit", version = "0.14.0", optional = true }` change the version to `0.15.4`.
> 3. Save the changes and build espanso as normal. It should now work perfectly on KDE Plasma with Wayland.

You, lakoliu, are a true hero! I can confirm that this fixed the issue. Finally I can use espanso again! 🙂

I'm sure your PR will be accepted, so I'll close this issue.
@lakoliu You are a life saver! Can confirm it works on Fedora 36 Kinoite (KDE Plasma Wayland) :heart: 
@lakoliu thanks!
Just for completeness:
```
# Clone repo:
mkdir git
cd git
git clone https://github.com/espanso/espanso.git
cd espanso
# compile:
cargo make --env NO_X11=true --profile release build-binary
cd ~/git/espanso/target/release # or where ever you cloned it.....
# Copy to correct place:
sudo cp espanso /usr/bin/espanso
# Then:
sudo setcap "cap_dac_override+p" $(which espanso)
```
My Espanso sprang to life and started working!!!!
@xircon (And _espanso service register_ if you want it to autostart. 😉)
Already done, ages ago :smile: That is why it sprang to life.


Fix patch:
diff --git a/Cargo.lock b/Cargo.lock
index 6d414c0d..3a57e66c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -591,7 +591,7 @@ dependencies = [
 
 [[package]]
 name = "espanso"
-version = "2.2.0"
+version = "2.2.1"
 dependencies = [
  "anyhow",
  "caps",
diff --git a/espanso-detect/src/win32/mod.rs b/espanso-detect/src/win32/mod.rs
index 6271b323..2bbe711e 100644
--- a/espanso-detect/src/win32/mod.rs
+++ b/espanso-detect/src/win32/mod.rs
@@ -176,7 +176,7 @@ impl Source for Win32Source {
 
   fn eventloop(&self, event_callback: SourceCallback) -> Result<()> {
     assert!(
-      self.handle.is_null(),
+      !self.handle.is_null(),
       "Attempt to start Win32Source eventloop without initialization"
     );
 
diff --git a/espanso-ui/src/win32/mod.rs b/espanso-ui/src/win32/mod.rs
index 7b1bbf96..b616ad68 100644
--- a/espanso-ui/src/win32/mod.rs
+++ b/espanso-ui/src/win32/mod.rs
@@ -198,7 +198,7 @@ impl UIEventLoop for Win32EventLoop {
     // Make sure the run() method is called in the same thread as initialize()
     if let Some(init_id) = self.init_thread_id.borrow() {
       assert!(
-        !(init_id != &std::thread::current().id()),
+        init_id == &std::thread::current().id(),
         "Win32EventLoop run() and initialize() methods should be called in the same thread"
       );
     }
diff --git a/espanso/Cargo.toml b/espanso/Cargo.toml
index 5efb1e42..4958b557 100644
--- a/espanso/Cargo.toml
+++ b/espanso/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "espanso"
-version = "2.2.0"
+version = "2.2.1"
 authors = ["Federico Terzi <federicoterzi96@gmail.com>"]
 license = "GPL-3.0"
 description = "Cross-platform Text Expander written in Rust"
diff --git a/snapcraft.yaml b/snapcraft.yaml
index 3a1e7bca..04519826 100644
--- a/snapcraft.yaml
+++ b/snapcraft.yaml
@@ -1,5 +1,5 @@
 name: espanso
-version: 2.2.0
+version: 2.2.1
 summary: A Cross-platform Text Expander written in Rust
 description: |
   espanso is a Cross-platform, Text Expander written in Rust.


Test patch: