Skip to content

Commit ea30e18

Browse files
crowlKatsdsherret
andauthored
refactor: update deno_core for error refactor (#26867)
Closes #26171 --------- Co-authored-by: David Sherret <[email protected]>
1 parent 814da49 commit ea30e18

File tree

214 files changed

+3786
-4209
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

214 files changed

+3786
-4209
lines changed

Cargo.lock

Lines changed: 91 additions & 66 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ repository = "https://github.com/denoland/deno"
4848

4949
[workspace.dependencies]
5050
deno_ast = { version = "=0.44.0", features = ["transpiling"] }
51-
deno_core = { version = "0.327.0" }
51+
deno_core = { version = "0.330.0" }
5252

5353
deno_bench_util = { version = "0.178.0", path = "./bench_util" }
54-
deno_config = { version = "=0.42.0", features = ["workspace", "sync"] }
54+
deno_config = { version = "=0.43.0", features = ["workspace", "sync"] }
5555
deno_lockfile = "=0.24.0"
5656
deno_media_type = { version = "0.2.3", features = ["module_specifier"] }
5757
deno_npm = "=0.27.0"
@@ -63,10 +63,10 @@ deno_terminal = "0.2.0"
6363
napi_sym = { version = "0.114.0", path = "./ext/napi/sym" }
6464
test_util = { package = "test_server", path = "./tests/util/server" }
6565

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

7171
# exts
7272
deno_broadcast_channel = { version = "0.178.0", path = "./ext/broadcast_channel" }
@@ -119,7 +119,7 @@ dashmap = "5.5.3"
119119
data-encoding = "2.3.3"
120120
data-url = "=0.3.1"
121121
deno_cache_dir = "=0.16.0"
122-
deno_error = "=0.5.2"
122+
deno_error = "=0.5.3"
123123
deno_package_json = { version = "0.4.0", default-features = false }
124124
deno_unsync = "0.4.2"
125125
dlopen2 = "0.6.1"

cli/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ serde_json.workspace = true
6262
zstd.workspace = true
6363
glibc_version = "0.1.2"
6464
flate2 = { workspace = true, features = ["default"] }
65+
deno_error.workspace = true
6566

6667
[target.'cfg(windows)'.build-dependencies]
6768
winapi.workspace = true
@@ -72,9 +73,9 @@ deno_ast = { workspace = true, features = ["bundler", "cjs", "codegen", "proposa
7273
deno_cache_dir.workspace = true
7374
deno_config.workspace = true
7475
deno_core = { workspace = true, features = ["include_js_files_for_snapshotting"] }
75-
deno_doc = { version = "=0.161.3", features = ["rust", "comrak"] }
76+
deno_doc = { version = "=0.164.0", features = ["rust", "comrak"] }
7677
deno_error.workspace = true
77-
deno_graph = { version = "=0.86.9" }
78+
deno_graph = { version = "=0.87.0" }
7879
deno_lint = { version = "=0.68.2", features = ["docs"] }
7980
deno_lockfile.workspace = true
8081
deno_npm.workspace = true
@@ -124,7 +125,7 @@ http.workspace = true
124125
http-body.workspace = true
125126
http-body-util.workspace = true
126127
hyper-util.workspace = true
127-
import_map = { version = "=0.20.1", features = ["ext"] }
128+
import_map = { version = "=0.21.0", features = ["ext"] }
128129
indexmap.workspace = true
129130
jsonc-parser = { workspace = true, features = ["cst", "serde"] }
130131
jupyter_runtime = { package = "runtimelib", version = "=0.19.0", features = ["tokio-runtime"] }

cli/args/lockfile.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use deno_core::error::AnyError;
1010
use deno_core::parking_lot::Mutex;
1111
use deno_core::parking_lot::MutexGuard;
1212
use deno_core::serde_json;
13+
use deno_error::JsErrorBox;
1314
use deno_lockfile::Lockfile;
1415
use deno_lockfile::WorkspaceMemberConfig;
1516
use deno_package_json::PackageJsonDepValue;
@@ -59,6 +60,14 @@ impl<'a, T> std::ops::DerefMut for Guard<'a, T> {
5960
}
6061
}
6162

63+
#[derive(Debug, thiserror::Error, deno_error::JsError)]
64+
#[error("Failed writing lockfile")]
65+
#[class(inherit)]
66+
struct AtomicWriteFileWithRetriesError {
67+
#[source]
68+
source: std::io::Error,
69+
}
70+
6271
impl CliLockfile {
6372
/// Get the inner deno_lockfile::Lockfile.
6473
pub fn lock(&self) -> Guard<Lockfile> {
@@ -78,7 +87,7 @@ impl CliLockfile {
7887
self.lockfile.lock().overwrite
7988
}
8089

81-
pub fn write_if_changed(&self) -> Result<(), AnyError> {
90+
pub fn write_if_changed(&self) -> Result<(), JsErrorBox> {
8291
if self.skip_write {
8392
return Ok(());
8493
}
@@ -96,7 +105,9 @@ impl CliLockfile {
96105
&bytes,
97106
cache::CACHE_PERM,
98107
)
99-
.context("Failed writing lockfile.")?;
108+
.map_err(|source| {
109+
JsErrorBox::from_err(AtomicWriteFileWithRetriesError { source })
110+
})?;
100111
lockfile.has_content_changed = false;
101112
Ok(())
102113
}
@@ -255,7 +266,7 @@ impl CliLockfile {
255266
})
256267
}
257268

258-
pub fn error_if_changed(&self) -> Result<(), AnyError> {
269+
pub fn error_if_changed(&self) -> Result<(), JsErrorBox> {
259270
if !self.frozen {
260271
return Ok(());
261272
}
@@ -267,9 +278,7 @@ impl CliLockfile {
267278
let diff = crate::util::diff::diff(&contents, &new_contents);
268279
// has an extra newline at the end
269280
let diff = diff.trim_end();
270-
Err(deno_core::anyhow::anyhow!(
271-
"The lockfile is out of date. Run `deno install --frozen=false`, or rerun with `--frozen=false` to update it.\nchanges:\n{diff}"
272-
))
281+
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}")))
273282
} else {
274283
Ok(())
275284
}

cli/args/mod.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use deno_ast::SourceMapOption;
2626
use deno_cache_dir::file_fetcher::CacheSetting;
2727
pub use deno_config::deno_json::BenchConfig;
2828
pub use deno_config::deno_json::ConfigFile;
29+
use deno_config::deno_json::ConfigFileError;
2930
use deno_config::deno_json::FmtConfig;
3031
pub use deno_config::deno_json::FmtOptionsConfig;
3132
use deno_config::deno_json::LintConfig;
@@ -55,6 +56,7 @@ use deno_core::error::AnyError;
5556
use deno_core::resolve_url_or_path;
5657
use deno_core::serde_json;
5758
use deno_core::url::Url;
59+
use deno_error::JsErrorBox;
5860
use deno_graph::GraphKind;
5961
pub use deno_json::check_warn_tsconfig;
6062
use deno_lint::linter::LintConfig as DenoLintConfig;
@@ -604,7 +606,8 @@ pub fn create_default_npmrc() -> Arc<ResolvedNpmRc> {
604606
})
605607
}
606608

607-
#[derive(Error, Debug, Clone)]
609+
#[derive(Error, Debug, Clone, deno_error::JsError)]
610+
#[class(generic)]
608611
pub enum RootCertStoreLoadError {
609612
#[error(
610613
"Unknown certificate store \"{0}\" specified (allowed: \"system,mozilla\")"
@@ -1104,7 +1107,7 @@ impl CliOptions {
11041107
pkg_json_dep_resolution,
11051108
specified_import_map: cli_arg_specified_import_map,
11061109
},
1107-
|path| Ok(std::fs::read_to_string(path)?),
1110+
|path| std::fs::read_to_string(path).map_err(JsErrorBox::from_err),
11081111
)?)
11091112
}
11101113

@@ -1246,11 +1249,14 @@ impl CliOptions {
12461249

12471250
pub fn node_modules_dir(
12481251
&self,
1249-
) -> Result<Option<NodeModulesDirMode>, AnyError> {
1252+
) -> Result<
1253+
Option<NodeModulesDirMode>,
1254+
deno_config::deno_json::NodeModulesDirParseError,
1255+
> {
12501256
if let Some(flag) = self.flags.node_modules_dir {
12511257
return Ok(Some(flag));
12521258
}
1253-
self.workspace().node_modules_dir().map_err(Into::into)
1259+
self.workspace().node_modules_dir()
12541260
}
12551261

12561262
pub fn vendor_dir_path(&self) -> Option<&PathBuf> {
@@ -1260,7 +1266,7 @@ impl CliOptions {
12601266
pub fn resolve_ts_config_for_emit(
12611267
&self,
12621268
config_type: TsConfigType,
1263-
) -> Result<TsConfigForEmit, AnyError> {
1269+
) -> Result<TsConfigForEmit, ConfigFileError> {
12641270
self.workspace().resolve_ts_config_for_emit(config_type)
12651271
}
12661272

@@ -1289,7 +1295,7 @@ impl CliOptions {
12891295

12901296
pub fn to_compiler_option_types(
12911297
&self,
1292-
) -> Result<Vec<deno_graph::ReferrerImports>, AnyError> {
1298+
) -> Result<Vec<deno_graph::ReferrerImports>, serde_json::Error> {
12931299
self
12941300
.workspace()
12951301
.to_compiler_option_types()

cli/build.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ mod ts {
1313
use std::path::Path;
1414
use std::path::PathBuf;
1515

16-
use deno_core::error::custom_error;
17-
use deno_core::error::AnyError;
1816
use deno_core::op2;
1917
use deno_core::OpState;
18+
use deno_error::JsErrorBox;
2019
use serde::Serialize;
2120

2221
use super::*;
@@ -53,7 +52,7 @@ mod ts {
5352
fn op_script_version(
5453
_state: &mut OpState,
5554
#[string] _arg: &str,
56-
) -> Result<Option<String>, AnyError> {
55+
) -> Result<Option<String>, JsErrorBox> {
5756
Ok(Some("1".to_string()))
5857
}
5958

@@ -72,7 +71,7 @@ mod ts {
7271
fn op_load(
7372
state: &mut OpState,
7473
#[string] load_specifier: &str,
75-
) -> Result<LoadResponse, AnyError> {
74+
) -> Result<LoadResponse, JsErrorBox> {
7675
let op_crate_libs = state.borrow::<HashMap<&str, PathBuf>>();
7776
let path_dts = state.borrow::<PathBuf>();
7877
let re_asset = lazy_regex::regex!(r"asset:/{3}lib\.(\S+)\.d\.ts");
@@ -93,26 +92,29 @@ mod ts {
9392
// if it comes from an op crate, we were supplied with the path to the
9493
// file.
9594
let path = if let Some(op_crate_lib) = op_crate_libs.get(lib) {
96-
PathBuf::from(op_crate_lib).canonicalize()?
95+
PathBuf::from(op_crate_lib)
96+
.canonicalize()
97+
.map_err(JsErrorBox::from_err)?
9798
// otherwise we will generate the path ourself
9899
} else {
99100
path_dts.join(format!("lib.{lib}.d.ts"))
100101
};
101-
let data = std::fs::read_to_string(path)?;
102+
let data =
103+
std::fs::read_to_string(path).map_err(JsErrorBox::from_err)?;
102104
Ok(LoadResponse {
103105
data,
104106
version: "1".to_string(),
105107
// this corresponds to `ts.ScriptKind.TypeScript`
106108
script_kind: 3,
107109
})
108110
} else {
109-
Err(custom_error(
111+
Err(JsErrorBox::new(
110112
"InvalidSpecifier",
111113
format!("An invalid specifier was requested: {}", load_specifier),
112114
))
113115
}
114116
} else {
115-
Err(custom_error(
117+
Err(JsErrorBox::new(
116118
"InvalidSpecifier",
117119
format!("An invalid specifier was requested: {}", load_specifier),
118120
))

cli/cache/mod.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use deno_ast::MediaType;
88
use deno_cache_dir::file_fetcher::CacheSetting;
99
use deno_cache_dir::file_fetcher::FetchNoFollowErrorKind;
1010
use deno_cache_dir::file_fetcher::FileOrRedirect;
11-
use deno_core::error::AnyError;
1211
use deno_core::futures;
1312
use deno_core::futures::FutureExt;
1413
use deno_core::ModuleSpecifier;
@@ -62,6 +61,7 @@ pub type GlobalHttpCache = deno_cache_dir::GlobalHttpCache<CliSys>;
6261
pub type LocalHttpCache = deno_cache_dir::LocalHttpCache<CliSys>;
6362
pub type LocalLspHttpCache = deno_cache_dir::LocalLspHttpCache<CliSys>;
6463
pub use deno_cache_dir::HttpCache;
64+
use deno_error::JsErrorBox;
6565

6666
pub struct FetchCacherOptions {
6767
pub file_header_overrides: HashMap<ModuleSpecifier, HashMap<String, String>>,
@@ -194,9 +194,9 @@ impl Loader for FetchCacher {
194194
LoaderCacheSetting::Use => None,
195195
LoaderCacheSetting::Reload => {
196196
if matches!(file_fetcher.cache_setting(), CacheSetting::Only) {
197-
return Err(deno_core::anyhow::anyhow!(
197+
return Err(deno_graph::source::LoadError::Other(Arc::new(JsErrorBox::generic(
198198
"Could not resolve version constraint using only cached data. Try running again without --cached-only"
199-
));
199+
))));
200200
}
201201
Some(CacheSetting::ReloadAll)
202202
}
@@ -262,28 +262,27 @@ impl Loader for FetchCacher {
262262
FetchNoFollowErrorKind::CacheSave { .. } |
263263
FetchNoFollowErrorKind::UnsupportedScheme { .. } |
264264
FetchNoFollowErrorKind::RedirectHeaderParse { .. } |
265-
FetchNoFollowErrorKind::InvalidHeader { .. } => Err(AnyError::from(err)),
265+
FetchNoFollowErrorKind::InvalidHeader { .. } => Err(deno_graph::source::LoadError::Other(Arc::new(JsErrorBox::from_err(err)))),
266266
FetchNoFollowErrorKind::NotCached { .. } => {
267267
if options.cache_setting == LoaderCacheSetting::Only {
268268
Ok(None)
269269
} else {
270-
Err(AnyError::from(err))
270+
Err(deno_graph::source::LoadError::Other(Arc::new(JsErrorBox::from_err(err))))
271271
}
272272
},
273273
FetchNoFollowErrorKind::ChecksumIntegrity(err) => {
274274
// convert to the equivalent deno_graph error so that it
275275
// enhances it if this is passed to deno_graph
276276
Err(
277-
deno_graph::source::ChecksumIntegrityError {
277+
deno_graph::source::LoadError::ChecksumIntegrity(deno_graph::source::ChecksumIntegrityError {
278278
actual: err.actual,
279279
expected: err.expected,
280-
}
281-
.into(),
280+
}),
282281
)
283282
}
284283
}
285284
},
286-
CliFetchNoFollowErrorKind::PermissionCheck(permission_check_error) => Err(AnyError::from(permission_check_error)),
285+
CliFetchNoFollowErrorKind::PermissionCheck(permission_check_error) => Err(deno_graph::source::LoadError::Other(Arc::new(JsErrorBox::from_err(permission_check_error)))),
287286
}
288287
})
289288
}

0 commit comments

Comments
 (0)