From db3ebb6b71a24abbacff075d113a7893018def11 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Tue, 22 Nov 2022 18:48:28 +0800 Subject: [PATCH] Better expect messages Signed-off-by: hi-rustin --- src/cargo/ops/cargo_add/mod.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/cargo/ops/cargo_add/mod.rs b/src/cargo/ops/cargo_add/mod.rs index 95d5954b2c0..a1614f00ec4 100644 --- a/src/cargo/ops/cargo_add/mod.rs +++ b/src/cargo/ops/cargo_add/mod.rs @@ -313,7 +313,10 @@ fn resolve_dependency( selected } else { let source = crate::sources::PathSource::new(&path, src.source_id()?, config); - let package = source.read_packages()?.pop().expect("at least one package"); + let package = source + .read_packages()? + .pop() + .expect("read_packages errors when no packages"); Dependency::from(package.summary()) }; selected @@ -603,7 +606,10 @@ fn infer_package_for_git_source( src: &dyn std::fmt::Display, ) -> CargoResult { let package = match packages.len() { - 0 => unreachable!(), + 0 => unreachable!( + "this function should only be called with packages from `GitSource::read_packages` \ + and that call should error for us when there are no packages" + ), 1 => packages.pop().expect("match ensured element is present"), _ => { let mut names: Vec<_> = packages