diff --git a/src/modules/sqlite/open.rs b/src/modules/sqlite/open.rs index c65ac8a..78a94fc 100644 --- a/src/modules/sqlite/open.rs +++ b/src/modules/sqlite/open.rs @@ -8,11 +8,13 @@ use either::Either; use rquickjs::{Ctx, FromJs, Null, Object, Result, Value}; use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions}; +use crate::utils::result::ResultExt; + use super::Database; static IN_MEMORY_DB_SEQ: AtomicUsize = AtomicUsize::new(0); -pub async fn open(options: OpenOptions) -> Result { +pub async fn open(ctx: Ctx<'_>, options: OpenOptions) -> Result { let mut connect_options = SqliteConnectOptions::new(); connect_options = connect_options .foreign_keys(options.foreign_keys) @@ -40,7 +42,10 @@ pub async fn open(options: OpenOptions) -> Result { .max_connections(options.max_connections) .min_connections(options.min_connections); - let pool = pool_options.connect_with(connect_options).await.unwrap(); + let pool = pool_options + .connect_with(connect_options) + .await + .or_throw_msg(&ctx, "Unable to open database")?; Ok(Database::new(pool)) }