mirror of
https://github.com/nushell/nushell
synced 2024-12-27 21:43:09 +00:00
Better error messages.
This commit is contained in:
parent
3f60c9d416
commit
96ef478fbc
3 changed files with 9 additions and 14 deletions
|
@ -251,7 +251,7 @@ impl ExternalCommand {
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
ShellError::labeled_error(
|
ShellError::labeled_error(
|
||||||
"Error: $it needs string data",
|
"$it needs string data",
|
||||||
"given something else",
|
"given something else",
|
||||||
self.name_tag.clone(),
|
self.name_tag.clone(),
|
||||||
)
|
)
|
||||||
|
|
|
@ -71,7 +71,7 @@ pub fn config(
|
||||||
if let Some(v) = get {
|
if let Some(v) = get {
|
||||||
let key = v.to_string();
|
let key = v.to_string();
|
||||||
let value = result.get(&key).ok_or_else(|| {
|
let value = result.get(&key).ok_or_else(|| {
|
||||||
ShellError::labeled_error(&format!("Missing key in config"), "key", v.tag())
|
ShellError::labeled_error("Missing key in config", "key", v.tag())
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let mut results = VecDeque::new();
|
let mut results = VecDeque::new();
|
||||||
|
@ -121,7 +121,7 @@ pub fn config(
|
||||||
config::write(&result, &configuration)?;
|
config::write(&result, &configuration)?;
|
||||||
} else {
|
} else {
|
||||||
return Err(ShellError::labeled_error(
|
return Err(ShellError::labeled_error(
|
||||||
"{} does not exist in config",
|
"Key does not exist in config",
|
||||||
"key",
|
"key",
|
||||||
v.tag(),
|
v.tag(),
|
||||||
));
|
));
|
||||||
|
|
|
@ -21,8 +21,8 @@ async fn docker(sub_command: &String, name: Tag) -> Result<Vec<Tagged<Value>>, S
|
||||||
"images" => docker_images(name),
|
"images" => docker_images(name),
|
||||||
_ => Err(ShellError::labeled_error(
|
_ => Err(ShellError::labeled_error(
|
||||||
"Unsupported Docker command",
|
"Unsupported Docker command",
|
||||||
format!("'{}'?", sub_command),
|
"unknown docker command",
|
||||||
name.span,
|
name,
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ fn process_docker_output(cmd_output: &str, tag: Tag) -> Result<Vec<Tagged<Value>
|
||||||
.filter(|s| s.trim() != "")
|
.filter(|s| s.trim() != "")
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let mut dict = TaggedDictBuilder::new(tag);
|
let mut dict = TaggedDictBuilder::new(&tag);
|
||||||
for (i, v) in values.iter().enumerate() {
|
for (i, v) in values.iter().enumerate() {
|
||||||
dict.insert(header[i].to_string(), Value::string(v.trim().to_string()));
|
dict.insert(header[i].to_string(), Value::string(v.trim().to_string()));
|
||||||
}
|
}
|
||||||
|
@ -92,18 +92,13 @@ impl Plugin for Docker {
|
||||||
if let Some(args) = callinfo.args.positional {
|
if let Some(args) = callinfo.args.positional {
|
||||||
match &args[0] {
|
match &args[0] {
|
||||||
Tagged {
|
Tagged {
|
||||||
item: Value::Primitive(Primitive::String(s)),
|
item: Value::Primitive(Primitive::String(command)),
|
||||||
..
|
..
|
||||||
} => match block_on(docker(&s, callinfo.name_tag)) {
|
} => match block_on(docker(&command, args[0].tag())) {
|
||||||
Ok(v) => return Ok(v.into_iter().map(ReturnSuccess::value).collect()),
|
Ok(v) => return Ok(v.into_iter().map(ReturnSuccess::value).collect()),
|
||||||
Err(e) => return Err(e),
|
Err(e) => return Err(e),
|
||||||
},
|
},
|
||||||
_ => {
|
_ => return Err(ShellError::type_error("string", args[0].tagged_type_name())),
|
||||||
return Err(ShellError::string(format!(
|
|
||||||
"Unrecognized type in params: {:?}",
|
|
||||||
args[0]
|
|
||||||
)))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue