{
const ENV_VAR_NAME: &str = "DENO_KV_ACCESS_TOKEN";
let Some(url) = path else {
- return Err(type_error("Missing database url"));
+ return Err(JsNativeError::type_error("Missing database url"));
};
let Ok(parsed_url) = Url::parse(&url) else {
- return Err(type_error(format!("Invalid database url: {}", url)));
+ return Err(JsNativeError::type_error(format!("Invalid database url: {}", url)));
};
{
let mut state = state.borrow_mut();
let permissions = state.borrow_mut::();
- permissions.check_env(ENV_VAR_NAME)?;
- permissions.check_net_url(&parsed_url, "Deno.openKv")?;
+ permissions.check_env(ENV_VAR_NAME).map_err(JsNativeError::from_err)?;
+ permissions.check_net_url(&parsed_url, "Deno.openKv").map_err(JsNativeError::from_err)?;
}
let access_token = std::env::var(ENV_VAR_NAME)
.map_err(anyhow::Error::from)
.with_context(|| {
"Missing DENO_KV_ACCESS_TOKEN environment variable. Please set it to your access token from https://dash.deno.com/account."
- })?;
+ }).map_err(|e| JsNativeError::generic(e.to_string()))?;
let metadata_endpoint = MetadataEndpoint {
url: parsed_url.clone(),
@@ -210,7 +209,7 @@ impl DatabaseHandler
http1: false,
http2: true,
},
- )?;
+ ).map_err(JsNativeError::from_err)?;
let fetch_client = FetchClient(client);
let permissions = PermissionChecker {
diff --git a/ext/kv/sqlite.rs b/ext/kv/sqlite.rs
index 9de5209275c28c..4a3476e0b5b613 100644
--- a/ext/kv/sqlite.rs
+++ b/ext/kv/sqlite.rs
@@ -15,8 +15,7 @@ use std::sync::OnceLock;
use crate::DatabaseHandler;
use async_trait::async_trait;
-use deno_core::error::type_error;
-use deno_core::error::AnyError;
+use deno_core::error::JsNativeError;
use deno_core::unsync::spawn_blocking;
use deno_core::OpState;
use deno_path_util::normalize_path;
@@ -84,6 +83,8 @@ impl SqliteDbHandler {
}
}
+deno_core::js_error_wrapper!(SqliteBackendError, JsSqliteBackendError, "TypeError");
+
#[async_trait(?Send)]
impl DatabaseHandler for SqliteDbHandler {
type DB = denokv_sqlite::Sqlite;
@@ -92,12 +93,12 @@ impl DatabaseHandler for SqliteDbHandler {
&self,
state: Rc>,
path: Option,
- ) -> Result {
+ ) -> Result {
#[must_use = "the resolved return value to mitigate time-of-check to time-of-use issues"]
fn validate_path(
state: &RefCell,
path: Option,
- ) -> Result