slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
16.93k stars 565 forks source link

slint js: Panics when there is an exception inside callbacks #6222

Open sigmaSd opened 1 day ago

sigmaSd commented 1 day ago
import * as slint from "npm:slint-ui@1.7.2";

const ui = slint.loadSource(
  `
import { Button } from "std-widgets.slint";
export component Window {
  callback hello();
  Button {
    text: "Click Me";
    clicked => { root.hello();}
  }
}`,
  "main.js",
);
const window = new ui.Window();
window.hello = () => {
  throw new Error("nice error");
};
await window.run();

deno run -A a.ts

thread '<unnamed>' panicked at api/node/src/interpreter/component_instance.rs:151:30:
called `Result::unwrap()` on an `Err` value: Error { status: GenericFailure, reason: "", maybe_raw: 0x0 }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
fish: Job 1, 'deno -A a.ts' terminated by signal SIGABRT (Abort)

Instead of seeing the error and its js stacktrace, rust panics with the above message

sigmaSd commented 1 day ago

this unwrap https://github.com/slint-ui/slint/blob/e842a25c8152766cb741cf005636ae950c5e1261/api/node/src/interpreter/component_instance.rs#L151 should simply changed to return an error instead