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

Merged
merged 45 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
bb277c9
update exts and runtime
crowlKats Nov 11, 2024
f8b335d
Merge branch 'main' into update-deno-core-error-rework
crowlKats Nov 23, 2024
b1442f4
Merge branch 'main' into update-deno-core-error-rework
crowlKats Nov 23, 2024
5a742d1
fix up runtime
crowlKats Nov 23, 2024
8fc695b
start some cli work
crowlKats Nov 23, 2024
884728d
Merge branch 'main' into update-deno-core-error-rework
crowlKats Dec 12, 2024
097bdac
progress
crowlKats Dec 13, 2024
8eab8de
Merge branch 'main' into update-deno-core-error-rework
crowlKats Dec 17, 2024
a193bd0
Merge branch 'main' into update-deno-core-error-rework
crowlKats Dec 18, 2024
a62427c
progress
crowlKats Dec 18, 2024
71ae511
progress
crowlKats Dec 19, 2024
3c807d8
fixes
crowlKats Dec 19, 2024
5c8f3ca
fixes
crowlKats Dec 21, 2024
ec41a08
Merge branch 'main' into update-deno-core-error-rework
dsherret Jan 6, 2025
625d0b1
some fixes
dsherret Jan 6, 2025
683af6a
fixes
crowlKats Jan 6, 2025
ef845de
Merge branch 'main' into update-deno-core-error-rework
crowlKats Jan 6, 2025
8374c23
fixes
crowlKats Jan 6, 2025
4c9495d
fixes
crowlKats Jan 6, 2025
ba58f99
fix windows compile errors
dsherret Jan 6, 2025
e7932c8
fix jsr tests
dsherret Jan 6, 2025
26182dc
Update two failing tests
dsherret Jan 6, 2025
5903a80
fixes
crowlKats Jan 7, 2025
c0ec4be
fixes
crowlKats Jan 7, 2025
de804d7
fmt
crowlKats Jan 7, 2025
f922392
Update
dsherret Jan 7, 2025
0d522ad
Merge branch 'main' into update-deno-core-error-rework
dsherret Jan 7, 2025
357c8dd
updates for windows
dsherret Jan 7, 2025
1be0c66
fixes
crowlKats Jan 7, 2025
769c6dc
Merge branch 'main' into update-deno-core-error-rework
crowlKats Jan 7, 2025
5da864a
fixes
crowlKats Jan 7, 2025
dc4c33f
fixes
crowlKats Jan 7, 2025
23fc64c
fix bare node builtin test
dsherret Jan 8, 2025
9fb8621
use git deps
crowlKats Jan 8, 2025
ef031d0
fmt
crowlKats Jan 8, 2025
2e50f1f
fix lsp tests
crowlKats Jan 8, 2025
1bd9539
clean
crowlKats Jan 8, 2025
624686f
Lint.
dsherret Jan 8, 2025
70bae74
try deno_core patch
crowlKats Jan 8, 2025
35f961b
fix
crowlKats Jan 8, 2025
8cf8f15
fix
crowlKats Jan 8, 2025
a7be9b8
update deps
crowlKats Jan 8, 2025
cf37831
fmt
crowlKats Jan 8, 2025
72c812e
Merge branch 'main' into update-deno-core-error-rework
crowlKats Jan 8, 2025
b001f6e
fix lock
crowlKats Jan 8, 2025
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
128 changes: 87 additions & 41 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 12 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ repository = "https://github.com/denoland/deno"

[workspace.dependencies]
deno_ast = { version = "=0.44.0", features = ["transpiling"] }
deno_core = { version = "0.327.0" }
deno_core = { version = "0.329.0" }

deno_bench_util = { version = "0.178.0", path = "./bench_util" }
deno_config = { version = "=0.42.0", features = ["workspace", "sync"] }
Expand All @@ -63,10 +63,10 @@ deno_terminal = "0.2.0"
napi_sym = { version = "0.114.0", path = "./ext/napi/sym" }
test_util = { package = "test_server", path = "./tests/util/server" }

denokv_proto = "0.8.4"
denokv_remote = "0.8.4"
denokv_proto = "0.9.0"
denokv_remote = "0.9.0"
# denokv_sqlite brings in bundled sqlite if we don't disable the default features
denokv_sqlite = { default-features = false, version = "0.8.4" }
denokv_sqlite = { default-features = false, version = "0.9.0" }

# exts
deno_broadcast_channel = { version = "0.178.0", path = "./ext/broadcast_channel" }
Expand Down Expand Up @@ -119,7 +119,7 @@ dashmap = "5.5.3"
data-encoding = "2.3.3"
data-url = "=0.3.1"
deno_cache_dir = "=0.16.0"
deno_error = "=0.5.2"
deno_error = "=0.5.3"
deno_package_json = { version = "0.4.0", default-features = false }
deno_unsync = "0.4.2"
dlopen2 = "0.6.1"
Expand Down Expand Up @@ -342,3 +342,10 @@ opt-level = 3
opt-level = 3
[profile.release.package.zstd-sys]
opt-level = 3

[patch.crates-io]
deno_graph = { git = "https://github.com/denoland/deno_graph", branch = "more-specific-errors" }
deno_config = { git = "https://github.com/denoland/deno_config", branch = "error-rework" }
deno_core = { git = "https://github.com/crowlKats/deno_core", branch = "revert-js_class_and_message_to_exception" }
deno_ops = { git = "https://github.com/crowlKats/deno_core", branch = "revert-js_class_and_message_to_exception" }
serde_v8 = { git = "https://github.com/crowlKats/deno_core", branch = "revert-js_class_and_message_to_exception" }
3 changes: 2 additions & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ serde_json.workspace = true
zstd.workspace = true
glibc_version = "0.1.2"
flate2 = { workspace = true, features = ["default"] }
deno_error.workspace = true

[target.'cfg(windows)'.build-dependencies]
winapi.workspace = true
Expand Down Expand Up @@ -124,7 +125,7 @@ http.workspace = true
http-body.workspace = true
http-body-util.workspace = true
hyper-util.workspace = true
import_map = { version = "=0.20.1", features = ["ext"] }
import_map = { version = "=0.21.0", features = ["ext"] }
indexmap.workspace = true
jsonc-parser = { workspace = true, features = ["cst", "serde"] }
jupyter_runtime = { package = "runtimelib", version = "=0.19.0", features = ["tokio-runtime"] }
Expand Down
21 changes: 15 additions & 6 deletions cli/args/lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use deno_core::error::AnyError;
use deno_core::parking_lot::Mutex;
use deno_core::parking_lot::MutexGuard;
use deno_core::serde_json;
use deno_error::JsErrorBox;
use deno_lockfile::Lockfile;
use deno_lockfile::WorkspaceMemberConfig;
use deno_package_json::PackageJsonDepValue;
Expand Down Expand Up @@ -59,6 +60,14 @@ impl<'a, T> std::ops::DerefMut for Guard<'a, T> {
}
}

#[derive(Debug, thiserror::Error, deno_error::JsError)]
#[error("Failed writing lockfile")]
#[class(inherit)]
struct AtomicWriteFileWithRetriesError {
#[source]
source: std::io::Error,
}

impl CliLockfile {
/// Get the inner deno_lockfile::Lockfile.
pub fn lock(&self) -> Guard<Lockfile> {
Expand All @@ -78,7 +87,7 @@ impl CliLockfile {
self.lockfile.lock().overwrite
}

pub fn write_if_changed(&self) -> Result<(), AnyError> {
pub fn write_if_changed(&self) -> Result<(), JsErrorBox> {
if self.skip_write {
return Ok(());
}
Expand All @@ -96,7 +105,9 @@ impl CliLockfile {
&bytes,
cache::CACHE_PERM,
)
.context("Failed writing lockfile.")?;
.map_err(|source| {
JsErrorBox::from_err(AtomicWriteFileWithRetriesError { source })
})?;
lockfile.has_content_changed = false;
Ok(())
}
Expand Down Expand Up @@ -255,7 +266,7 @@ impl CliLockfile {
})
}

pub fn error_if_changed(&self) -> Result<(), AnyError> {
pub fn error_if_changed(&self) -> Result<(), JsErrorBox> {
if !self.frozen {
return Ok(());
}
Expand All @@ -267,9 +278,7 @@ impl CliLockfile {
let diff = crate::util::diff::diff(&contents, &new_contents);
// has an extra newline at the end
let diff = diff.trim_end();
Err(deno_core::anyhow::anyhow!(
"The lockfile is out of date. Run `deno install --frozen=false`, or rerun with `--frozen=false` to update it.\nchanges:\n{diff}"
))
Err(JsErrorBox::generic(format!("The lockfile is out of date. Run `deno install --frozen=false`, or rerun with `--frozen=false` to update it.\nchanges:\n{diff}")))
} else {
Ok(())
}
Expand Down
18 changes: 12 additions & 6 deletions cli/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use deno_ast::SourceMapOption;
use deno_cache_dir::file_fetcher::CacheSetting;
pub use deno_config::deno_json::BenchConfig;
pub use deno_config::deno_json::ConfigFile;
use deno_config::deno_json::ConfigFileError;
use deno_config::deno_json::FmtConfig;
pub use deno_config::deno_json::FmtOptionsConfig;
use deno_config::deno_json::LintConfig;
Expand Down Expand Up @@ -55,6 +56,7 @@ use deno_core::error::AnyError;
use deno_core::resolve_url_or_path;
use deno_core::serde_json;
use deno_core::url::Url;
use deno_error::JsErrorBox;
use deno_graph::GraphKind;
pub use deno_json::check_warn_tsconfig;
use deno_lint::linter::LintConfig as DenoLintConfig;
Expand Down Expand Up @@ -604,7 +606,8 @@ pub fn create_default_npmrc() -> Arc<ResolvedNpmRc> {
})
}

#[derive(Error, Debug, Clone)]
#[derive(Error, Debug, Clone, deno_error::JsError)]
#[class(generic)]
pub enum RootCertStoreLoadError {
#[error(
"Unknown certificate store \"{0}\" specified (allowed: \"system,mozilla\")"
Expand Down Expand Up @@ -1104,7 +1107,7 @@ impl CliOptions {
pkg_json_dep_resolution,
specified_import_map: cli_arg_specified_import_map,
},
|path| Ok(std::fs::read_to_string(path)?),
|path| std::fs::read_to_string(path).map_err(JsErrorBox::from_err),
)?)
}

Expand Down Expand Up @@ -1246,11 +1249,14 @@ impl CliOptions {

pub fn node_modules_dir(
&self,
) -> Result<Option<NodeModulesDirMode>, AnyError> {
) -> Result<
Option<NodeModulesDirMode>,
deno_config::deno_json::NodeModulesDirParseError,
> {
if let Some(flag) = self.flags.node_modules_dir {
return Ok(Some(flag));
}
self.workspace().node_modules_dir().map_err(Into::into)
self.workspace().node_modules_dir()
}

pub fn vendor_dir_path(&self) -> Option<&PathBuf> {
Expand All @@ -1260,7 +1266,7 @@ impl CliOptions {
pub fn resolve_ts_config_for_emit(
&self,
config_type: TsConfigType,
) -> Result<TsConfigForEmit, AnyError> {
) -> Result<TsConfigForEmit, ConfigFileError> {
self.workspace().resolve_ts_config_for_emit(config_type)
}

Expand Down Expand Up @@ -1289,7 +1295,7 @@ impl CliOptions {

pub fn to_compiler_option_types(
&self,
) -> Result<Vec<deno_graph::ReferrerImports>, AnyError> {
) -> Result<Vec<deno_graph::ReferrerImports>, serde_json::Error> {
self
.workspace()
.to_compiler_option_types()
Expand Down
18 changes: 10 additions & 8 deletions cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ mod ts {
use std::path::Path;
use std::path::PathBuf;

use deno_core::error::custom_error;
use deno_core::error::AnyError;
use deno_core::op2;
use deno_core::OpState;
use deno_error::JsErrorBox;
use serde::Serialize;

use super::*;
Expand Down Expand Up @@ -53,7 +52,7 @@ mod ts {
fn op_script_version(
_state: &mut OpState,
#[string] _arg: &str,
) -> Result<Option<String>, AnyError> {
) -> Result<Option<String>, JsErrorBox> {
Ok(Some("1".to_string()))
}

Expand All @@ -72,7 +71,7 @@ mod ts {
fn op_load(
state: &mut OpState,
#[string] load_specifier: &str,
) -> Result<LoadResponse, AnyError> {
) -> Result<LoadResponse, JsErrorBox> {
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 @@ -93,26 +92,29 @@ 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(JsErrorBox::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(JsErrorBox::from_err)?;
Ok(LoadResponse {
data,
version: "1".to_string(),
// this corresponds to `ts.ScriptKind.TypeScript`
script_kind: 3,
})
} else {
Err(custom_error(
Err(JsErrorBox::new(
"InvalidSpecifier",
format!("An invalid specifier was requested: {}", load_specifier),
))
}
} else {
Err(custom_error(
Err(JsErrorBox::new(
"InvalidSpecifier",
format!("An invalid specifier was requested: {}", load_specifier),
))
Expand Down
17 changes: 8 additions & 9 deletions cli/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use deno_ast::MediaType;
use deno_cache_dir::file_fetcher::CacheSetting;
use deno_cache_dir::file_fetcher::FetchNoFollowErrorKind;
use deno_cache_dir::file_fetcher::FileOrRedirect;
use deno_core::error::AnyError;
use deno_core::futures;
use deno_core::futures::FutureExt;
use deno_core::ModuleSpecifier;
Expand Down Expand Up @@ -62,6 +61,7 @@ pub type GlobalHttpCache = deno_cache_dir::GlobalHttpCache<CliSys>;
pub type LocalHttpCache = deno_cache_dir::LocalHttpCache<CliSys>;
pub type LocalLspHttpCache = deno_cache_dir::LocalLspHttpCache<CliSys>;
pub use deno_cache_dir::HttpCache;
use deno_error::JsErrorBox;

pub struct FetchCacherOptions {
pub file_header_overrides: HashMap<ModuleSpecifier, HashMap<String, String>>,
Expand Down Expand Up @@ -194,9 +194,9 @@ impl Loader for FetchCacher {
LoaderCacheSetting::Use => None,
LoaderCacheSetting::Reload => {
if matches!(file_fetcher.cache_setting(), CacheSetting::Only) {
return Err(deno_core::anyhow::anyhow!(
return Err(deno_graph::source::LoadError::Other(Arc::new(JsErrorBox::generic(
"Could not resolve version constraint using only cached data. Try running again without --cached-only"
));
))));
}
Some(CacheSetting::ReloadAll)
}
Expand Down Expand Up @@ -262,28 +262,27 @@ impl Loader for FetchCacher {
FetchNoFollowErrorKind::CacheSave { .. } |
FetchNoFollowErrorKind::UnsupportedScheme { .. } |
FetchNoFollowErrorKind::RedirectHeaderParse { .. } |
FetchNoFollowErrorKind::InvalidHeader { .. } => Err(AnyError::from(err)),
FetchNoFollowErrorKind::InvalidHeader { .. } => Err(deno_graph::source::LoadError::Other(Arc::new(JsErrorBox::from_err(err)))),
FetchNoFollowErrorKind::NotCached { .. } => {
if options.cache_setting == LoaderCacheSetting::Only {
Ok(None)
} else {
Err(AnyError::from(err))
Err(deno_graph::source::LoadError::Other(Arc::new(JsErrorBox::from_err(err))))
}
},
FetchNoFollowErrorKind::ChecksumIntegrity(err) => {
// convert to the equivalent deno_graph error so that it
// enhances it if this is passed to deno_graph
Err(
deno_graph::source::ChecksumIntegrityError {
deno_graph::source::LoadError::ChecksumIntegrity(deno_graph::source::ChecksumIntegrityError {
actual: err.actual,
expected: err.expected,
}
.into(),
}),
)
}
}
},
CliFetchNoFollowErrorKind::PermissionCheck(permission_check_error) => Err(AnyError::from(permission_check_error)),
CliFetchNoFollowErrorKind::PermissionCheck(permission_check_error) => Err(deno_graph::source::LoadError::Other(Arc::new(JsErrorBox::from_err(permission_check_error)))),
}
})
}
Expand Down
Loading
Loading