@@ -153,7 +153,10 @@ pub fn load_pnp_manifest(p: &Path) -> Result<Manifest, Error> {
153153pub 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
197200pub 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