Skip to content

Commit 507111d

Browse files
committed
fix: impl JsError for more errors
1 parent 9b9c9aa commit 507111d

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::collections::HashSet;
1212
use capacity_builder::CapacityDisplay;
1313
use capacity_builder::StringAppendable;
1414
use capacity_builder::StringBuilder;
15+
use deno_error::JsError;
1516
use deno_semver::package::PackageNv;
1617
use deno_semver::CowVec;
1718
use deno_semver::SmallStackString;
@@ -28,7 +29,8 @@ pub mod npm_rc;
2829
pub mod registry;
2930
pub mod resolution;
3031

31-
#[derive(Debug, Error)]
32+
#[derive(Debug, Error, Clone, JsError)]
33+
#[class(type)]
3234
#[error("Invalid npm package id '{text}'. {message}")]
3335
pub struct NpmPackageIdDeserializationError {
3436
message: String,

src/resolution/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub use snapshot::incomplete_snapshot_from_lockfile;
1212
pub use snapshot::snapshot_from_lockfile;
1313
pub use snapshot::AddPkgReqsOptions;
1414
pub use snapshot::AddPkgReqsResult;
15+
pub use snapshot::IncompleteSnapshotFromLockfileError;
1516
pub use snapshot::NpmPackagesPartitioned;
1617
pub use snapshot::NpmResolutionSnapshot;
1718
pub use snapshot::PackageCacheFolderIdNotFoundError;

src/resolution/snapshot.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -812,9 +812,10 @@ fn name_without_path(name: &str) -> &str {
812812
}
813813
}
814814

815-
#[derive(Debug, Error)]
815+
#[derive(Debug, Error, Clone, JsError)]
816816
pub enum IncompleteSnapshotFromLockfileError {
817817
#[error(transparent)]
818+
#[class(inherit)]
818819
PackageIdDeserialization(#[from] NpmPackageIdDeserializationError),
819820
}
820821

@@ -884,7 +885,8 @@ pub fn incomplete_snapshot_from_lockfile(
884885
})
885886
}
886887

887-
#[derive(Debug, Clone, Error)]
888+
#[derive(Debug, Clone, Error, JsError)]
889+
#[class(type)]
888890
#[error("Integrity check failed for package: \"{package_display_id}\". Unable to verify that the package
889891
is the same as when the lockfile was generated.
890892
@@ -904,18 +906,22 @@ pub struct IntegrityCheckFailedError {
904906
pub filename: String,
905907
}
906908

907-
#[derive(Debug, Error, Clone)]
909+
#[derive(Debug, Error, Clone, JsError)]
908910
pub enum SnapshotFromLockfileError {
909911
#[error(transparent)]
912+
#[class(inherit)]
910913
PackageInfoLoad(#[from] NpmRegistryPackageInfoLoadError),
911914
#[error("Could not find '{}' specified in the lockfile.", .source.0)]
915+
#[class(inherit)]
912916
VersionNotFound {
913917
#[from]
914918
source: NpmPackageVersionNotFound,
915919
},
916920
#[error("The lockfile is corrupt. Remove the lockfile to regenerate it.")]
921+
#[class(inherit)]
917922
PackageIdNotFound(#[from] PackageIdNotFoundError),
918923
#[error(transparent)]
924+
#[class(inherit)]
919925
IntegrityCheckFailed(#[from] IntegrityCheckFailedError),
920926
}
921927

0 commit comments

Comments
 (0)