From b656fe66d08ba8270ea69b27a79e2f40287fdf35 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Wed, 21 Sep 2022 22:29:31 +0100 Subject: [PATCH] Switch back to `get_string` as it reports more errors --- src/bin/cargo/main.rs | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/bin/cargo/main.rs b/src/bin/cargo/main.rs index b8e286e91676..45874d38a35c 100644 --- a/src/bin/cargo/main.rs +++ b/src/bin/cargo/main.rs @@ -1,7 +1,7 @@ #![warn(rust_2018_idioms)] // while we're getting used to 2018 #![allow(clippy::all)] -use cargo::util::config::{ConfigError, ConfigErrorKind, Value}; +use cargo::util::config::{ConfigError, ConfigErrorKind}; use cargo::util::toml::StringOrVec; use cargo::util::CliError; use cargo::util::{self, closest_msg, command_prelude, CargoResult, CliResult, Config}; @@ -63,22 +63,26 @@ fn builtin_aliases_execs(cmd: &str) -> Option<&(&str, &str, &str)> { /// 4. If still no command is found, return `None`. fn aliased_command(config: &Config, command: &str) -> CargoResult>> { let alias_name = format!("alias.{command}"); - let user_alias = match config.get::>(&alias_name) { - Ok(record) => Some( + let user_alias = match config.get_string(&alias_name) { + Ok(Some(record)) => Some( record .val .split_whitespace() .map(|s| s.to_string()) .collect(), ), - Err(e) => match e.downcast_ref::().map(|e| e.kind()) { - // Just report we cannot find anything. - Some(ConfigErrorKind::MissingKey) => None, - // Alias might be set as an toml array, fallback and try it. - Some(ConfigErrorKind::UnexpectedValue) => config.get::>(&alias_name)?, - // A unrecoverable error, e.g. TOML parsing error. Relay it to the user. - Some(ConfigErrorKind::Custom) | None => return Err(e), - }, + // Just report we cannot find anything. + Ok(None) => None, + // Alias might be set as an toml array, fallback and try it. + Err(e) + if e.downcast_ref::() + .map(|e| matches!(e.kind(), ConfigErrorKind::UnexpectedValue)) + .unwrap_or_default() => + { + config.get::>(&alias_name)? + } + // A unrecoverable error, e.g. TOML parsing error. Relay it to the user. + Err(e) => return Err(e), }; let result = user_alias.or_else(|| {