antoyo / relm

Idiomatic, GTK+-based, GUI library, inspired by Elm, written in Rust
MIT License
2.43k stars 78 forks source link

Show GTK init error instead of hiding it #254

Closed emmanueltouzery closed 3 years ago

emmanueltouzery commented 3 years ago

i'm seeing this issue on my system and it may be a problem caused by my setup, not necessarily a bug in relm.

I see sometimes Widget::run returning Err(()) when using X11 (but I never saw it when using wayland).

For instance, on my sway+wayland setup:

relm/relm-examples $ cargo run --example clock

works just fine.

But GDK_BACKEND=X11 cargo run --example clock crashes with:

thread 'main' panicked at 'Win::run failed: ()', examples/clock.rs:110:18 note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

The backtrace is not super useful:

thread 'main' panicked at 'Win::run failed: ()', examples/clock.rs:110:18
stack backtrace:
   0: rust_begin_unwind
             at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/panicking.rs:483
   1: core::panicking::panic_fmt
             at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/panicking.rs:85
   2: core::option::expect_none_failed
             at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/option.rs:1234
   3: core::result::Result<T,E>::expect
             at /home/emmanuel/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/result.rs:933
   4: clock::main
             at ./examples/clock.rs:110
   5: core::ops::function::FnOnce::call_once
             at /home/emmanuel/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:227
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

It's the same at least with the headerbar example too.

I also ran GDK_BACKEND=X11 strace -f cargo run --example clock >& st.txt and I attach the st.txt file.

In which cases can Widget::run return Err(())?

I'm reproducing this on the latest master btw.

st.txt

antoyo commented 3 years ago

This line is probably the error. Can you modify the code in a local clone to see the error?

By the way, we should probably change this as to not hide the error.

emmanueltouzery commented 3 years ago

yes... I did this:

    let e = gtk::init();
    eprintln!("###### {:?}", e);
    e.unwrap();

And I get:

###### Err(BoolError { message: "Failed to initialize GTK", filename: "/home/emmanuel/.cargo/registry/src/github.com-1ecc6299db9ec823/gtk-0.9.2/src/rt.rs", function: "gtk::rt", line: 129 })
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: BoolError { message: "Failed to initialize GTK", filename: "/home/emmanuel/.cargo/registry/src/github.com-1ecc6299db9ec823/gtk-0.9.2/src/rt.rs", function: "gtk::rt", line: 129 }', /home/emmanuel/home/relm/src/lib.rs:334:7
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

So it's a GTK/X11 issue. Probably really something with my system. Weird...

emmanueltouzery commented 3 years ago

Right, so I ran with GDK_BACKEND=X11 not x11 (case problem).

However I've seen this issue also when run directly on X11, but through flatpak. That was definitely another issue. In that case I suspect it was a failure due to the fact that flatpak has a app-id and prevents the app from running twice at the same time, or something like that.

antoyo commented 3 years ago

Seems like a GTK issue indeed. I don't use Wayland so I cannot help you. I suggest you ask on GTK channels as they'll be better able to help you.

emmanueltouzery commented 3 years ago

Yes, it's really a gtk issue, but possibly we could keep this bug open, but change it as a feature request that relm would return some error details?

gtk-rs returns: https://gtk-rs.org/docs/glib/error/struct.BoolError.html

Which seems to contain a string message. Maybe relm ::run() could return a string instead of () in the error component? I now believe the error I've seen with flatpak was due to the app-id and refusing to run the same app twice, but it was very confusing when I hit that issue.

antoyo commented 3 years ago

Sure. I renamed the issue.

antoyo commented 3 years ago

Fixed by #275 .