catch panics at base functions to integrate with other fatal errors.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
@@ -6,10 +6,11 @@ mod serve;
|
||||
|
||||
extern crate conduit_core as conduit;
|
||||
|
||||
use std::{future::Future, pin::Pin, sync::Arc};
|
||||
use std::{panic::AssertUnwindSafe, pin::Pin, sync::Arc};
|
||||
|
||||
use conduit::{Result, Server};
|
||||
use conduit::{Error, Result, Server};
|
||||
use conduit_service::Services;
|
||||
use futures::{Future, FutureExt, TryFutureExt};
|
||||
|
||||
conduit::mod_ctor! {}
|
||||
conduit::mod_dtor! {}
|
||||
@@ -17,15 +18,27 @@ conduit::rustc_flags_capture! {}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "Rust" fn start(server: &Arc<Server>) -> Pin<Box<dyn Future<Output = Result<Arc<Services>>> + Send>> {
|
||||
Box::pin(run::start(server.clone()))
|
||||
AssertUnwindSafe(run::start(server.clone()))
|
||||
.catch_unwind()
|
||||
.map_err(Error::from_panic)
|
||||
.unwrap_or_else(Err)
|
||||
.boxed()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "Rust" fn stop(services: Arc<Services>) -> Pin<Box<dyn Future<Output = Result<()>> + Send>> {
|
||||
Box::pin(run::stop(services))
|
||||
AssertUnwindSafe(run::stop(services))
|
||||
.catch_unwind()
|
||||
.map_err(Error::from_panic)
|
||||
.unwrap_or_else(Err)
|
||||
.boxed()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "Rust" fn run(services: &Arc<Services>) -> Pin<Box<dyn Future<Output = Result<()>> + Send>> {
|
||||
Box::pin(run::run(services.clone()))
|
||||
AssertUnwindSafe(run::run(services.clone()))
|
||||
.catch_unwind()
|
||||
.map_err(Error::from_panic)
|
||||
.unwrap_or_else(Err)
|
||||
.boxed()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user