From 568dd132fb0a47f9afb11bffec341c7481dda75c Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 16 Jul 2024 18:32:41 -0400 Subject: 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. --- ext/node/package_json.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'ext/node/package_json.rs') 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> = 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)), } } -- cgit v1.2.3