Skip to content

Commit

Permalink
fix: impl JsError for more errors (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret authored Jan 10, 2025
1 parent 9b9c9aa commit 3e5e068
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::collections::HashSet;
use capacity_builder::CapacityDisplay;
use capacity_builder::StringAppendable;
use capacity_builder::StringBuilder;
use deno_error::JsError;
use deno_semver::package::PackageNv;
use deno_semver::CowVec;
use deno_semver::SmallStackString;
Expand All @@ -28,7 +29,8 @@ pub mod npm_rc;
pub mod registry;
pub mod resolution;

#[derive(Debug, Error)]
#[derive(Debug, Error, Clone, JsError)]
#[class(type)]
#[error("Invalid npm package id '{text}'. {message}")]
pub struct NpmPackageIdDeserializationError {
message: String,
Expand Down
2 changes: 2 additions & 0 deletions src/resolution/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ pub use snapshot::incomplete_snapshot_from_lockfile;
pub use snapshot::snapshot_from_lockfile;
pub use snapshot::AddPkgReqsOptions;
pub use snapshot::AddPkgReqsResult;
pub use snapshot::IncompleteSnapshotFromLockfileError;
pub use snapshot::IntegrityCheckFailedError;
pub use snapshot::NpmPackagesPartitioned;
pub use snapshot::NpmResolutionSnapshot;
pub use snapshot::PackageCacheFolderIdNotFoundError;
Expand Down
12 changes: 9 additions & 3 deletions src/resolution/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -812,9 +812,10 @@ fn name_without_path(name: &str) -> &str {
}
}

#[derive(Debug, Error)]
#[derive(Debug, Error, Clone, JsError)]
pub enum IncompleteSnapshotFromLockfileError {
#[error(transparent)]
#[class(inherit)]
PackageIdDeserialization(#[from] NpmPackageIdDeserializationError),
}

Expand Down Expand Up @@ -884,7 +885,8 @@ pub fn incomplete_snapshot_from_lockfile(
})
}

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

#[derive(Debug, Error, Clone)]
#[derive(Debug, Error, Clone, JsError)]
pub enum SnapshotFromLockfileError {
#[error(transparent)]
#[class(inherit)]
PackageInfoLoad(#[from] NpmRegistryPackageInfoLoadError),
#[error("Could not find '{}' specified in the lockfile.", .source.0)]
#[class(inherit)]
VersionNotFound {
#[from]
source: NpmPackageVersionNotFound,
},
#[error("The lockfile is corrupt. Remove the lockfile to regenerate it.")]
#[class(inherit)]
PackageIdNotFound(#[from] PackageIdNotFoundError),
#[error(transparent)]
#[class(inherit)]
IntegrityCheckFailed(#[from] IntegrityCheckFailedError),
}

Expand Down

0 comments on commit 3e5e068

Please sign in to comment.