Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: update deno_core for error refactor #26867

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 27 additions & 44 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ repository = "https://github.com/denoland/deno"

[workspace.dependencies]
deno_ast = { version = "=0.43.3", features = ["transpiling"] }
deno_core = { version = "0.318.0" }
deno_core = { version = "0.319.0" }

deno_bench_util = { version = "0.171.0", path = "./bench_util" }
deno_lockfile = "=0.23.1"
Expand Down Expand Up @@ -326,3 +326,11 @@ opt-level = 3
opt-level = 3
[profile.release.package.zstd-sys]
opt-level = 3

[patch.crates-io]
deno_core = { path = "../deno_core/core" }
deno_ops = { path = "../deno_core/ops" }
deno_js_error = { path = "../deno_core/js_error" }
serde_v8 = { path = "../deno_core/serde_v8" }
v8 = { path = "../rusty_v8" }

15 changes: 7 additions & 8 deletions cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ mod shared;

mod ts {
use super::*;
use deno_core::error::custom_error;
use deno_core::error::AnyError;
use deno_core::error::JsNativeError;
use deno_core::op2;
use deno_core::OpState;
use serde::Serialize;
Expand Down Expand Up @@ -51,7 +50,7 @@ mod ts {
fn op_script_version(
_state: &mut OpState,
#[string] _arg: &str,
) -> Result<Option<String>, AnyError> {
) -> Result<Option<String>, JsNativeError> {
Ok(Some("1".to_string()))
}

Expand All @@ -70,7 +69,7 @@ mod ts {
fn op_load(
state: &mut OpState,
#[string] load_specifier: &str,
) -> Result<LoadResponse, AnyError> {
) -> Result<LoadResponse, JsNativeError> {
let op_crate_libs = state.borrow::<HashMap<&str, PathBuf>>();
let path_dts = state.borrow::<PathBuf>();
let re_asset = lazy_regex::regex!(r"asset:/{3}lib\.(\S+)\.d\.ts");
Expand All @@ -91,26 +90,26 @@ mod ts {
// if it comes from an op crate, we were supplied with the path to the
// file.
let path = if let Some(op_crate_lib) = op_crate_libs.get(lib) {
PathBuf::from(op_crate_lib).canonicalize()?
PathBuf::from(op_crate_lib).canonicalize().map_err(JsNativeError::from_err)?
// otherwise we will generate the path ourself
} else {
path_dts.join(format!("lib.{lib}.d.ts"))
};
let data = std::fs::read_to_string(path)?;
let data = std::fs::read_to_string(path).map_err(JsNativeError::from_err)?;
Ok(LoadResponse {
data,
version: "1".to_string(),
// this corresponds to `ts.ScriptKind.TypeScript`
script_kind: 3,
})
} else {
Err(custom_error(
Err(JsNativeError::new(
"InvalidSpecifier",
format!("An invalid specifier was requested: {}", load_specifier),
))
}
} else {
Err(custom_error(
Err(JsNativeError::new(
"InvalidSpecifier",
format!("An invalid specifier was requested: {}", load_specifier),
))
Expand Down
4 changes: 2 additions & 2 deletions cli/module_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1065,11 +1065,11 @@ impl<TGraphContainer: ModuleGraphContainer> NodeRequireLoader
&self,
permissions: &mut dyn deno_runtime::deno_node::NodePermissions,
path: &'a Path,
) -> Result<std::borrow::Cow<'a, Path>, AnyError> {
) -> Result<Cow<'a, Path>, deno_runtime::deno_permissions::PermissionCheckError> {
if let Ok(url) = deno_path_util::url_from_file_path(path) {
// allow reading if it's in the module graph
if self.graph_container.graph().get(&url).is_some() {
return Ok(std::borrow::Cow::Borrowed(path));
return Ok(Cow::Borrowed(path));
}
}
self.npm_resolver.ensure_read_permission(permissions, path)
Expand Down
4 changes: 2 additions & 2 deletions cli/npm/byonm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ impl CliNpmResolver for CliByonmNpmResolver {
&self,
permissions: &mut dyn NodePermissions,
path: &'a Path,
) -> Result<Cow<'a, Path>, AnyError> {
) -> Result<Cow<'a, Path>, deno_runtime::deno_permissions::PermissionCheckError> {
if !path
.components()
.any(|c| c.as_os_str().to_ascii_lowercase() == "node_modules")
{
permissions.check_read_path(path).map_err(Into::into)
permissions.check_read_path(path)
} else {
Ok(Cow::Borrowed(path))
}
Expand Down
2 changes: 1 addition & 1 deletion cli/npm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ pub trait CliNpmResolver: NpmResolver {
&self,
permissions: &mut dyn NodePermissions,
path: &'a Path,
) -> Result<Cow<'a, Path>, AnyError>;
) -> Result<Cow<'a, Path>, deno_runtime::deno_permissions::PermissionCheckError>;

/// Returns a hash returning the state of the npm resolver
/// or `None` if the state currently can't be determined.
Expand Down
2 changes: 1 addition & 1 deletion cli/standalone/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ impl NodeRequireLoader for EmbeddedModuleLoader {
&self,
permissions: &mut dyn deno_runtime::deno_node::NodePermissions,
path: &'a std::path::Path,
) -> Result<Cow<'a, std::path::Path>, AnyError> {
) -> Result<Cow<'a, std::path::Path>, deno_runtime::deno_permissions::PermissionCheckError> {
if self.shared.modules.has_file(path) {
// allow reading if the file is in the snapshot
return Ok(Cow::Borrowed(path));
Expand Down
2 changes: 1 addition & 1 deletion cli/tools/bench/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use crate::util::path::matches_pattern_or_exact_path;
use crate::worker::CliMainWorkerFactory;

use deno_config::glob::WalkEntry;
use deno_core::error::generic_error;
use deno_core::error::AnyError;
use deno_core::error::JsError;
use deno_core::error::JsNativeError::generic;
use deno_core::futures::future;
use deno_core::futures::stream;
use deno_core::futures::StreamExt;
Expand Down
28 changes: 11 additions & 17 deletions ext/broadcast_channel/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::path::PathBuf;
use std::rc::Rc;

use async_trait::async_trait;
use deno_core::error::JsNativeError;
use deno_core::op2;
use deno_core::JsBuffer;
use deno_core::OpState;
Expand All @@ -20,18 +21,22 @@ use tokio::sync::mpsc::error::SendError as MpscSendError;

pub const UNSTABLE_FEATURE_NAME: &str = "broadcast-channel";

#[derive(Debug, thiserror::Error)]
#[derive(Debug, thiserror::Error, deno_core::JsError)]
pub enum BroadcastChannelError {
#[class(inherit)]
#[error(transparent)]
Resource(deno_core::error::AnyError),
Resource(#[from] #[inherit] deno_core::error::ResourceError),
#[class(GENERIC)]
#[error(transparent)]
MPSCSendError(MpscSendError<Box<dyn std::fmt::Debug + Send + Sync>>),
#[class(GENERIC)]
#[error(transparent)]
BroadcastSendError(
BroadcastSendError<Box<dyn std::fmt::Debug + Send + Sync>>,
),
#[class(inherit)]
#[error(transparent)]
Other(deno_core::error::AnyError),
Other(#[inherit] JsNativeError),
}

impl<T: std::fmt::Debug + Send + Sync + 'static> From<MpscSendError<T>>
Expand Down Expand Up @@ -101,10 +106,7 @@ pub fn op_broadcast_unsubscribe<BC>(
where
BC: BroadcastChannel + 'static,
{
let resource = state
.resource_table
.get::<BC::Resource>(rid)
.map_err(BroadcastChannelError::Resource)?;
let resource = state.resource_table.get::<BC::Resource>(rid)?;
let bc = state.borrow::<BC>();
bc.unsubscribe(&resource)
}
Expand All @@ -119,11 +121,7 @@ pub async fn op_broadcast_send<BC>(
where
BC: BroadcastChannel + 'static,
{
let resource = state
.borrow()
.resource_table
.get::<BC::Resource>(rid)
.map_err(BroadcastChannelError::Resource)?;
let resource = state.borrow().resource_table.get::<BC::Resource>(rid)?;
let bc = state.borrow().borrow::<BC>().clone();
bc.send(&resource, name, buf.to_vec()).await
}
Expand All @@ -137,11 +135,7 @@ pub async fn op_broadcast_recv<BC>(
where
BC: BroadcastChannel + 'static,
{
let resource = state
.borrow()
.resource_table
.get::<BC::Resource>(rid)
.map_err(BroadcastChannelError::Resource)?;
let resource = state.borrow().resource_table.get::<BC::Resource>(rid)?;
let bc = state.borrow().borrow::<BC>().clone();
bc.recv(&resource).await
}
Expand Down
Loading