Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ pub fn load_pnp_manifest(p: &Path) -> Result<Manifest, Error> {
pub fn init_pnp_manifest(manifest: &mut Manifest, p: &Path) {
manifest.manifest_path = p.to_path_buf();

manifest.manifest_dir = p.parent().expect("Should have a parent directory").to_owned();
manifest.manifest_dir = p
.parent()
.unwrap_or_else(|| panic!("Should have a parent directory for path {}", p.display()))
.to_owned();

for (name, ranges) in manifest.package_registry_data.iter_mut() {
for (reference, info) in ranges.iter_mut() {
Expand Down Expand Up @@ -195,8 +198,9 @@ pub fn is_dependency_tree_root<'a>(manifest: &'a Manifest, locator: &'a PackageL
}

pub fn find_locator<'a>(manifest: &'a Manifest, path: &Path) -> Option<&'a PackageLocator> {
let rel_path = pathdiff::diff_paths(path, &manifest.manifest_dir)
.expect("Assertion failed: Provided path should be absolute");
let rel_path = pathdiff::diff_paths(path, &manifest.manifest_dir).unwrap_or_else(|| {
panic!("Assertion failed: Provided path should be absolute but received {}", path.display())
});

if let Some(regex) = &manifest.ignore_pattern_data {
if regex.0.is_match(&util::normalize_path(rel_path.to_string_lossy())).unwrap() {
Expand All @@ -211,13 +215,13 @@ pub fn get_package<'a>(
manifest: &'a Manifest,
locator: &PackageLocator,
) -> Result<&'a PackageInformation, Error> {
let references = manifest
.package_registry_data
.get(&locator.name)
.expect("Should have an entry in the package registry");
let references = manifest.package_registry_data.get(&locator.name).unwrap_or_else(|| {
panic!("Should have an entry in the package registry for {}", locator.name)
});

let info =
references.get(&locator.reference).expect("Should have an entry in the package registry");
let info = references.get(&locator.reference).unwrap_or_else(|| {
panic!("Should have an entry in the package registry for {}", locator.reference)
});

Ok(info)
}
Expand Down
Loading