Skip to content

Commit

Permalink
Switch back to get_string as it reports more errors
Browse files Browse the repository at this point in the history
  • Loading branch information
weihanglo committed Sep 21, 2022
1 parent 985c485 commit b656fe6
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/bin/cargo/main.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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<Option<Vec<String>>> {
let alias_name = format!("alias.{command}");
let user_alias = match config.get::<Value<String>>(&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::<ConfigError>().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::<Option<_>>(&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::<ConfigError>()
.map(|e| matches!(e.kind(), ConfigErrorKind::UnexpectedValue))
.unwrap_or_default() =>
{
config.get::<Option<_>>(&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(|| {
Expand Down

0 comments on commit b656fe6

Please sign in to comment.