From 6a4c72696526250b6dca37946ebf7c76bba56315 Mon Sep 17 00:00:00 2001 From: luaneko Date: Sat, 28 Jun 2025 04:11:33 +1000 Subject: [PATCH] Properly report panic by resuming unwind --- Cargo.toml | 4 ++-- crates/lb/Cargo.toml | 1 + crates/lb/src/lib.rs | 4 ++-- src/main.rs | 5 ++++- tests/{test.lua => main.lua} | 0 tests/{test.rs => main.rs} | 9 ++++++--- 6 files changed, 15 insertions(+), 8 deletions(-) rename tests/{test.lua => main.lua} (100%) rename tests/{test.rs => main.rs} (85%) diff --git a/Cargo.toml b/Cargo.toml index 309ae38..80fc095 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +31,7 @@ dev.panic = "abort" release.panic = "abort" [[test]] -name = "test" +name = "main" harness = false [features] @@ -44,7 +44,7 @@ tokio-console = ["dep:console-subscriber"] [dependencies] clap = { version = "4.5.40", features = ["derive", "env"] } console-subscriber = { version = "0.4.1", optional = true } -lb = { path = "crates/lb" } +lb = { path = "crates/lb", features = ["runtime"] } luajit = { path = "crates/luajit", features = ["runtime"] } mimalloc = "0.1.47" owo-colors = "4.2.1" diff --git a/crates/lb/Cargo.toml b/crates/lb/Cargo.toml index 36f6dc6..1d2e451 100644 --- a/crates/lb/Cargo.toml +++ b/crates/lb/Cargo.toml @@ -8,6 +8,7 @@ homepage.workspace = true repository.workspace = true [features] +runtime = ["tokio/rt"] task = ["tokio/rt", "tokio/time"] fs = ["tokio/fs", "dep:walkdir", "dep:globset", "dep:tempfile"] net = ["tokio/net"] diff --git a/crates/lb/src/lib.rs b/crates/lb/src/lib.rs index 42952a0..c74751f 100644 --- a/crates/lb/src/lib.rs +++ b/crates/lb/src/lib.rs @@ -1,12 +1,12 @@ //! luby standard library #![warn(missing_docs)] -pub mod runtime; - #[cfg(feature = "task")] pub mod chan; #[cfg(feature = "fs")] pub mod fs; #[cfg(feature = "net")] pub mod net; +#[cfg(feature = "runtime")] +pub mod runtime; #[cfg(feature = "task")] pub mod task; diff --git a/src/main.rs b/src/main.rs index b4b21d1..a49f69a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -153,7 +153,10 @@ fn main() -> Result<(), ExitCode> { tokio.block_on(async { lua.await; - main.await.unwrap() + match main.await { + Ok(res) => res, + Err(err) => panic::resume_unwind(err.into_panic()), + } }) } diff --git a/tests/test.lua b/tests/main.lua similarity index 100% rename from tests/test.lua rename to tests/main.lua diff --git a/tests/test.rs b/tests/main.rs similarity index 85% rename from tests/test.rs rename to tests/main.rs index 5d09542..8ae2a2e 100644 --- a/tests/test.rs +++ b/tests/main.rs @@ -1,7 +1,7 @@ use luajit::Chunk; use owo_colors::OwoColorize; use std::{ - fs, + fs, panic, process::{self, ExitCode}, }; @@ -13,7 +13,7 @@ fn main() -> ExitCode { rt.unhandled_error(error_cb).build().unwrap() }; - let path = "tests/test.lua"; + let path = "tests/main.lua"; let main = lua.spawn(async move |s| { if let Err(ref err) = s.load(Chunk::new(fs::read(path).unwrap()).path(path)) { s.report_error(err); @@ -30,7 +30,10 @@ fn main() -> ExitCode { tokio.block_on(async move { lua.await; - main.await.unwrap() + match main.await { + Ok(res) => res, + Err(err) => panic::resume_unwind(err.into_panic()), + } }) }