summaryrefslogtreecommitdiff
path: root/resolvers/node/errors.rs
diff options
context:
space:
mode:
authorhaturau <135221985+haturatu@users.noreply.github.com>2024-11-20 01:20:47 +0900
committerGitHub <noreply@github.com>2024-11-20 01:20:47 +0900
commit85719a67e59c7aa45bead26e4942d7df8b1b42d4 (patch)
treeface0aecaac53e93ce2f23b53c48859bcf1a36ec /resolvers/node/errors.rs
parent67697bc2e4a62a9670699fd18ad0dd8efc5bd955 (diff)
parent186b52731c6bb326c4d32905c5e732d082e83465 (diff)
Merge branch 'denoland:main' into main
Diffstat (limited to 'resolvers/node/errors.rs')
-rw-r--r--resolvers/node/errors.rs128
1 files changed, 27 insertions, 101 deletions
diff --git a/resolvers/node/errors.rs b/resolvers/node/errors.rs
index 4ba829eda..0f332d2c9 100644
--- a/resolvers/node/errors.rs
+++ b/resolvers/node/errors.rs
@@ -4,39 +4,13 @@ use std::borrow::Cow;
use std::fmt::Write;
use std::path::PathBuf;
+use boxed_error::Boxed;
use thiserror::Error;
use url::Url;
use crate::NodeModuleKind;
use crate::NodeResolutionMode;
-macro_rules! kinded_err {
- ($name:ident, $kind_name:ident) => {
- #[derive(Error, Debug)]
- #[error(transparent)]
- pub struct $name(pub Box<$kind_name>);
-
- impl $name {
- pub fn as_kind(&self) -> &$kind_name {
- &self.0
- }
-
- pub fn into_kind(self) -> $kind_name {
- *self.0
- }
- }
-
- impl<E> From<E> for $name
- where
- $kind_name: From<E>,
- {
- fn from(err: E) -> Self {
- $name(Box::new($kind_name::from(err)))
- }
- }
- };
-}
-
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[allow(non_camel_case_types)]
pub enum NodeJsErrorCode {
@@ -81,29 +55,6 @@ pub trait NodeJsErrorCoded {
fn code(&self) -> NodeJsErrorCode;
}
-kinded_err!(
- ResolvePkgSubpathFromDenoModuleError,
- ResolvePkgSubpathFromDenoModuleErrorKind
-);
-
-impl NodeJsErrorCoded for ResolvePkgSubpathFromDenoModuleError {
- fn code(&self) -> NodeJsErrorCode {
- use ResolvePkgSubpathFromDenoModuleErrorKind::*;
- match self.as_kind() {
- PackageSubpathResolve(e) => e.code(),
- UrlToNodeResolution(e) => e.code(),
- }
- }
-}
-
-#[derive(Debug, Error)]
-pub enum ResolvePkgSubpathFromDenoModuleErrorKind {
- #[error(transparent)]
- PackageSubpathResolve(#[from] PackageSubpathResolveError),
- #[error(transparent)]
- UrlToNodeResolution(#[from] UrlToNodeResolutionError),
-}
-
// todo(https://github.com/denoland/deno_core/issues/810): make this a TypeError
#[derive(Debug, Clone, Error)]
#[error(
@@ -125,7 +76,8 @@ impl NodeJsErrorCoded for InvalidModuleSpecifierError {
}
}
-kinded_err!(LegacyResolveError, LegacyResolveErrorKind);
+#[derive(Debug, Boxed)]
+pub struct LegacyResolveError(pub Box<LegacyResolveErrorKind>);
#[derive(Debug, Error)]
pub enum LegacyResolveErrorKind {
@@ -144,8 +96,6 @@ impl NodeJsErrorCoded for LegacyResolveError {
}
}
-kinded_err!(PackageFolderResolveError, PackageFolderResolveErrorKind);
-
#[derive(Debug, Error)]
#[error(
"Could not find package '{}' from referrer '{}'{}.",
@@ -209,6 +159,9 @@ impl NodeJsErrorCoded for PackageFolderResolveError {
}
}
+#[derive(Debug, Boxed)]
+pub struct PackageFolderResolveError(pub Box<PackageFolderResolveErrorKind>);
+
#[derive(Debug, Error)]
pub enum PackageFolderResolveErrorKind {
#[error(transparent)]
@@ -219,8 +172,6 @@ pub enum PackageFolderResolveErrorKind {
Io(#[from] PackageFolderResolveIoError),
}
-kinded_err!(PackageSubpathResolveError, PackageSubpathResolveErrorKind);
-
impl NodeJsErrorCoded for PackageSubpathResolveError {
fn code(&self) -> NodeJsErrorCode {
match self.as_kind() {
@@ -231,6 +182,9 @@ impl NodeJsErrorCoded for PackageSubpathResolveError {
}
}
+#[derive(Debug, Boxed)]
+pub struct PackageSubpathResolveError(pub Box<PackageSubpathResolveErrorKind>);
+
#[derive(Debug, Error)]
pub enum PackageSubpathResolveErrorKind {
#[error(transparent)]
@@ -275,8 +229,6 @@ impl NodeJsErrorCoded for PackageTargetNotFoundError {
}
}
-kinded_err!(PackageTargetResolveError, PackageTargetResolveErrorKind);
-
impl NodeJsErrorCoded for PackageTargetResolveError {
fn code(&self) -> NodeJsErrorCode {
match self.as_kind() {
@@ -289,6 +241,9 @@ impl NodeJsErrorCoded for PackageTargetResolveError {
}
}
+#[derive(Debug, Boxed)]
+pub struct PackageTargetResolveError(pub Box<PackageTargetResolveErrorKind>);
+
#[derive(Debug, Error)]
pub enum PackageTargetResolveErrorKind {
#[error(transparent)]
@@ -303,8 +258,6 @@ pub enum PackageTargetResolveErrorKind {
TypesNotFound(#[from] TypesNotFoundError),
}
-kinded_err!(PackageExportsResolveError, PackageExportsResolveErrorKind);
-
impl NodeJsErrorCoded for PackageExportsResolveError {
fn code(&self) -> NodeJsErrorCode {
match self.as_kind() {
@@ -314,6 +267,9 @@ impl NodeJsErrorCoded for PackageExportsResolveError {
}
}
+#[derive(Debug, Boxed)]
+pub struct PackageExportsResolveError(pub Box<PackageExportsResolveErrorKind>);
+
#[derive(Debug, Error)]
pub enum PackageExportsResolveErrorKind {
#[error(transparent)]
@@ -361,8 +317,6 @@ impl NodeJsErrorCoded for PackageJsonLoadError {
}
}
-kinded_err!(ClosestPkgJsonError, ClosestPkgJsonErrorKind);
-
impl NodeJsErrorCoded for ClosestPkgJsonError {
fn code(&self) -> NodeJsErrorCode {
match self.as_kind() {
@@ -372,6 +326,9 @@ impl NodeJsErrorCoded for ClosestPkgJsonError {
}
}
+#[derive(Debug, Boxed)]
+pub struct ClosestPkgJsonError(pub Box<ClosestPkgJsonErrorKind>);
+
#[derive(Debug, Error)]
pub enum ClosestPkgJsonErrorKind {
#[error(transparent)]
@@ -394,37 +351,6 @@ impl NodeJsErrorCoded for CanonicalizingPkgJsonDirError {
}
}
-#[derive(Debug, Error)]
-#[error("TypeScript files are not supported in npm packages: {specifier}")]
-pub struct TypeScriptNotSupportedInNpmError {
- pub specifier: Url,
-}
-
-impl NodeJsErrorCoded for TypeScriptNotSupportedInNpmError {
- fn code(&self) -> NodeJsErrorCode {
- NodeJsErrorCode::ERR_UNKNOWN_FILE_EXTENSION
- }
-}
-
-kinded_err!(UrlToNodeResolutionError, UrlToNodeResolutionErrorKind);
-
-impl NodeJsErrorCoded for UrlToNodeResolutionError {
- fn code(&self) -> NodeJsErrorCode {
- match self.as_kind() {
- UrlToNodeResolutionErrorKind::TypeScriptNotSupported(e) => e.code(),
- UrlToNodeResolutionErrorKind::ClosestPkgJson(e) => e.code(),
- }
- }
-}
-
-#[derive(Debug, Error)]
-pub enum UrlToNodeResolutionErrorKind {
- #[error(transparent)]
- TypeScriptNotSupported(#[from] TypeScriptNotSupportedInNpmError),
- #[error(transparent)]
- ClosestPkgJson(#[from] ClosestPkgJsonError),
-}
-
// todo(https://github.com/denoland/deno_core/issues/810): make this a TypeError
#[derive(Debug, Error)]
#[error(
@@ -446,7 +372,8 @@ impl NodeJsErrorCoded for PackageImportNotDefinedError {
}
}
-kinded_err!(PackageImportsResolveError, PackageImportsResolveErrorKind);
+#[derive(Debug, Boxed)]
+pub struct PackageImportsResolveError(pub Box<PackageImportsResolveErrorKind>);
#[derive(Debug, Error)]
pub enum PackageImportsResolveErrorKind {
@@ -471,8 +398,6 @@ impl NodeJsErrorCoded for PackageImportsResolveErrorKind {
}
}
-kinded_err!(PackageResolveError, PackageResolveErrorKind);
-
impl NodeJsErrorCoded for PackageResolveError {
fn code(&self) -> NodeJsErrorCode {
match self.as_kind() {
@@ -485,6 +410,9 @@ impl NodeJsErrorCoded for PackageResolveError {
}
}
+#[derive(Debug, Boxed)]
+pub struct PackageResolveError(pub Box<PackageResolveErrorKind>);
+
#[derive(Debug, Error)]
pub enum PackageResolveErrorKind {
#[error(transparent)]
@@ -515,7 +443,8 @@ pub struct DataUrlReferrerError {
pub source: url::ParseError,
}
-kinded_err!(NodeResolveError, NodeResolveErrorKind);
+#[derive(Debug, Boxed)]
+pub struct NodeResolveError(pub Box<NodeResolveErrorKind>);
#[derive(Debug, Error)]
pub enum NodeResolveErrorKind {
@@ -533,11 +462,10 @@ pub enum NodeResolveErrorKind {
TypesNotFound(#[from] TypesNotFoundError),
#[error(transparent)]
FinalizeResolution(#[from] FinalizeResolutionError),
- #[error(transparent)]
- UrlToNodeResolution(#[from] UrlToNodeResolutionError),
}
-kinded_err!(FinalizeResolutionError, FinalizeResolutionErrorKind);
+#[derive(Debug, Boxed)]
+pub struct FinalizeResolutionError(pub Box<FinalizeResolutionErrorKind>);
#[derive(Debug, Error)]
pub enum FinalizeResolutionErrorKind {
@@ -728,8 +656,6 @@ pub enum ResolvePkgJsonBinExportError {
MissingPkgJson { pkg_json_path: PathBuf },
#[error("Failed resolving binary export. {message}")]
InvalidBinProperty { message: String },
- #[error(transparent)]
- UrlToNodeResolution(#[from] UrlToNodeResolutionError),
}
#[derive(Debug, Error)]