@@ -60,6 +60,7 @@ pub(crate) fn compute_package_id_for_crate_id(
6060 enum ResolvedDependency {
6161 Found ( PackageId ) ,
6262 Ambiguous ( IndexSet < PackageLinkMetadata > ) ,
63+ NotFound ,
6364 }
6465
6566 /// Find a transitive dependency of `search_root` given its name (and maybe the version).
@@ -72,7 +73,7 @@ pub(crate) fn compute_package_id_for_crate_id(
7273 ) -> Option < PackageId > {
7374 match _find_transitive_dependency ( package_graph, search_root, name, version) {
7475 Ok ( ResolvedDependency :: Found ( id) ) => Some ( id) ,
75- Ok ( ResolvedDependency :: Ambiguous ( _) ) => None ,
76+ Ok ( ResolvedDependency :: Ambiguous ( _) | ResolvedDependency :: NotFound ) => None ,
7677 Err ( e) => {
7778 log_error ! (
7879 * e,
@@ -116,10 +117,7 @@ pub(crate) fn compute_package_id_for_crate_id(
116117 } )
117118 . collect ( ) ;
118119 if package_candidates. is_empty ( ) {
119- anyhow:: bail!(
120- "I could not find any crate named `{expected_link_name}` \
121- among the dependencies of {search_root}",
122- )
120+ return Ok ( ResolvedDependency :: NotFound ) ;
123121 }
124122 if package_candidates. len ( ) == 1 {
125123 return Ok ( ResolvedDependency :: Found (
@@ -178,19 +176,16 @@ pub(crate) fn compute_package_id_for_crate_id(
178176 package_id,
179177 & external_crate. name ,
180178 external_crate_version. as_ref ( ) ,
181- ) {
182- Ok ( ResolvedDependency :: Found ( id) ) => return Ok ( id) ,
183- Ok ( ResolvedDependency :: Ambiguous ( candidates) ) => Some ( candidates) ,
184- Err ( e) => {
185- log_error ! (
186- * e,
187- level: tracing:: Level :: WARN ,
188- external_crate. name = %external_crate. name,
189- external_crate. version = ?external_crate_version,
190- search_root = %package_id. repr( ) ,
191- "Failed to find transitive dependency"
192- ) ;
193- None
179+ ) ? {
180+ ResolvedDependency :: Found ( id) => return Ok ( id) ,
181+ ResolvedDependency :: Ambiguous ( candidates) => candidates,
182+ ResolvedDependency :: NotFound => {
183+ return Err ( anyhow ! (
184+ "I could not find any crate named `{}` \
185+ among the dependencies (either direct or transitive) of {}",
186+ external_crate. name,
187+ package_id. repr( )
188+ ) ) ;
194189 }
195190 } ;
196191
@@ -221,18 +216,12 @@ pub(crate) fn compute_package_id_for_crate_id(
221216 }
222217
223218 let candidates_list = ambiguous_candidates
224- . as_ref ( )
225- . map ( |candidates| {
226- let list = candidates
227- . iter ( )
228- . map ( |l| format ! ( "- {} v{} ({})" , l. name, l. version, l. id. repr( ) ) )
229- . collect :: < Vec < _ > > ( )
230- . join ( "\n " ) ;
231- format ! ( ":\n {list}\n " )
232- } )
233- . unwrap_or_else ( || ". " . to_owned ( ) ) ;
219+ . iter ( )
220+ . map ( |l| format ! ( "- {} v{} ({})" , l. name, l. version, l. id. repr( ) ) )
221+ . collect :: < Vec < _ > > ( )
222+ . join ( "\n " ) ;
234223 Err ( anyhow ! (
235- "There are multiple packages named `{}` among the dependencies of {}{} \
224+ "There are multiple packages named `{}` among the dependencies of {}: \n {} \n \
236225 In order to disambiguate among them, I need to know their versions.\n \
237226 Unfortunately, I couldn't extract the expected version for `{}` from HTML root URL included in the \
238227 JSON documentation for `{}`.\n \
0 commit comments