diff --git a/src/auto_extension.rs b/src/auto_extension.rs index acb7523..b996006 100644 --- a/src/auto_extension.rs +++ b/src/auto_extension.rs @@ -1,8 +1,9 @@ //! Automatic axtension loading use super::ffi; use crate::error::{check, to_sqlite_error}; -use crate::{Connection, Result}; +use crate::{Connection, Error, Result}; use std::os::raw::{c_char, c_int}; +use std::panic::catch_unwind; /// Automatic extension initialization routine pub type AutoExtension = fn(Connection) -> Result<()>; @@ -27,8 +28,12 @@ pub unsafe fn init_auto_extension( pz_err_msg: *mut *mut c_char, ax: AutoExtension, ) -> c_int { - let c = Connection::from_handle(db); - match c.and_then(ax) { + let r = catch_unwind(|| { + let c = Connection::from_handle(db); + c.and_then(ax) + }) + .unwrap_or_else(|_| Err(Error::UnwindingPanic)); + match r { Err(e) => to_sqlite_error(&e, pz_err_msg), _ => ffi::SQLITE_OK, } diff --git a/src/error.rs b/src/error.rs index a9d557c..2946382 100644 --- a/src/error.rs +++ b/src/error.rs @@ -102,8 +102,6 @@ pub enum Error { ModuleError(String), /// An unwinding panic occurs in an UDF (user-defined function). - #[cfg(feature = "functions")] - #[cfg_attr(docsrs, doc(cfg(feature = "functions")))] UnwindingPanic, /// An error returned when @@ -185,7 +183,6 @@ impl PartialEq for Error { (Error::InvalidQuery, Error::InvalidQuery) => true, #[cfg(feature = "vtab")] (Error::ModuleError(s1), Error::ModuleError(s2)) => s1 == s2, - #[cfg(feature = "functions")] (Error::UnwindingPanic, Error::UnwindingPanic) => true, #[cfg(feature = "functions")] (Error::GetAuxWrongType, Error::GetAuxWrongType) => true, @@ -318,7 +315,6 @@ impl fmt::Display for Error { Error::InvalidQuery => write!(f, "Query is not read-only"), #[cfg(feature = "vtab")] Error::ModuleError(ref desc) => write!(f, "{desc}"), - #[cfg(feature = "functions")] Error::UnwindingPanic => write!(f, "unwinding panic"), #[cfg(feature = "functions")] Error::GetAuxWrongType => write!(f, "get_aux called with wrong type"), @@ -375,7 +371,6 @@ impl error::Error for Error { #[cfg(feature = "vtab")] Error::ModuleError(_) => None, - #[cfg(feature = "functions")] Error::UnwindingPanic => None, #[cfg(feature = "functions")]