Skip to content

Commit b656fe6

Browse files
committed
Switch back to get_string as it reports more errors
1 parent 985c485 commit b656fe6

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/bin/cargo/main.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![warn(rust_2018_idioms)] // while we're getting used to 2018
22
#![allow(clippy::all)]
33

4-
use cargo::util::config::{ConfigError, ConfigErrorKind, Value};
4+
use cargo::util::config::{ConfigError, ConfigErrorKind};
55
use cargo::util::toml::StringOrVec;
66
use cargo::util::CliError;
77
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)> {
6363
/// 4. If still no command is found, return `None`.
6464
fn aliased_command(config: &Config, command: &str) -> CargoResult<Option<Vec<String>>> {
6565
let alias_name = format!("alias.{command}");
66-
let user_alias = match config.get::<Value<String>>(&alias_name) {
67-
Ok(record) => Some(
66+
let user_alias = match config.get_string(&alias_name) {
67+
Ok(Some(record)) => Some(
6868
record
6969
.val
7070
.split_whitespace()
7171
.map(|s| s.to_string())
7272
.collect(),
7373
),
74-
Err(e) => match e.downcast_ref::<ConfigError>().map(|e| e.kind()) {
75-
// Just report we cannot find anything.
76-
Some(ConfigErrorKind::MissingKey) => None,
77-
// Alias might be set as an toml array, fallback and try it.
78-
Some(ConfigErrorKind::UnexpectedValue) => config.get::<Option<_>>(&alias_name)?,
79-
// A unrecoverable error, e.g. TOML parsing error. Relay it to the user.
80-
Some(ConfigErrorKind::Custom) | None => return Err(e),
81-
},
74+
// Just report we cannot find anything.
75+
Ok(None) => None,
76+
// Alias might be set as an toml array, fallback and try it.
77+
Err(e)
78+
if e.downcast_ref::<ConfigError>()
79+
.map(|e| matches!(e.kind(), ConfigErrorKind::UnexpectedValue))
80+
.unwrap_or_default() =>
81+
{
82+
config.get::<Option<_>>(&alias_name)?
83+
}
84+
// A unrecoverable error, e.g. TOML parsing error. Relay it to the user.
85+
Err(e) => return Err(e),
8286
};
8387

8488
let result = user_alias.or_else(|| {

0 commit comments

Comments
 (0)