Skip to content

Commit b452548

Browse files
authored
chore: add recived path into panic info (#46)
* chore: add recived path into panic info * chore: update all panics
1 parent cbba833 commit b452548

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/lib.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ pub fn load_pnp_manifest(p: &Path) -> Result<Manifest, Error> {
153153
pub fn init_pnp_manifest(manifest: &mut Manifest, p: &Path) {
154154
manifest.manifest_path = p.to_path_buf();
155155

156-
manifest.manifest_dir = p.parent().expect("Should have a parent directory").to_owned();
156+
manifest.manifest_dir = p
157+
.parent()
158+
.unwrap_or_else(|| panic!("Should have a parent directory for path {}", p.display()))
159+
.to_owned();
157160

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

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

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

219-
let info =
220-
references.get(&locator.reference).expect("Should have an entry in the package registry");
222+
let info = references.get(&locator.reference).unwrap_or_else(|| {
223+
panic!("Should have an entry in the package registry for {}", locator.reference)
224+
});
221225

222226
Ok(info)
223227
}

0 commit comments

Comments
 (0)