diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2024-07-16 18:32:41 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-16 18:32:41 -0400 |
commit | 568dd132fb0a47f9afb11bffec341c7481dda75c (patch) | |
tree | a49456aca018a2ee7d184bd829bdb75209208d0c /ext/node/package_json.rs | |
parent | c9da27e147d0681724dd647593abbaa46417feb7 (diff) |
refactor(node): internally add `.code()` to node resolution errors (#24610)
This makes it easier to tell what kind of error something is (even for
deeply nested errors) and will help in the future once we add error
codes to the JS errors this returns.
Diffstat (limited to 'ext/node/package_json.rs')
-rw-r--r-- | ext/node/package_json.rs | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/ext/node/package_json.rs b/ext/node/package_json.rs index 8a88fe8f1..b28207db8 100644 --- a/ext/node/package_json.rs +++ b/ext/node/package_json.rs @@ -1,7 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. use deno_config::package_json::PackageJson; -use deno_config::package_json::PackageJsonLoadError; use deno_config::package_json::PackageJsonRc; use deno_fs::DenoConfigFsAdapter; use std::cell::RefCell; @@ -10,6 +9,8 @@ use std::io::ErrorKind; use std::path::Path; use std::path::PathBuf; +use crate::errors::PackageJsonLoadError; + // use a thread local cache so that workers have their own distinct cache thread_local! { static CACHE: RefCell<HashMap<PathBuf, PackageJsonRc>> = RefCell::new(HashMap::new()); @@ -48,11 +49,9 @@ pub fn load_pkg_json( ); match result { Ok(pkg_json) => Ok(Some(pkg_json)), - Err(PackageJsonLoadError::Io { source, .. }) - if source.kind() == ErrorKind::NotFound => - { - Ok(None) - } - Err(err) => Err(err), + Err(deno_config::package_json::PackageJsonLoadError::Io { + source, .. + }) if source.kind() == ErrorKind::NotFound => Ok(None), + Err(err) => Err(PackageJsonLoadError(err)), } } |