mirror of
https://github.com/nushell/nushell.git
synced 2025-01-11 16:58:41 +01:00
Fix unsupported type message for some math related commands (#4672)
* Fix unsupported type message of some math related commands * changing the error form for UnsupportedInput * cargo fmt
This commit is contained in:
parent
0924975b4c
commit
b09acdb7f9
5
crates/nu-command/src/env/load_env.rs
vendored
5
crates/nu-command/src/env/load_env.rs
vendored
@ -75,7 +75,10 @@ impl Command for LoadEnv {
|
||||
}
|
||||
Ok(PipelineData::new(call.head))
|
||||
}
|
||||
_ => Err(ShellError::UnsupportedInput("Record".into(), span)),
|
||||
_ => Err(ShellError::UnsupportedInput(
|
||||
"Record not supported".into(),
|
||||
span,
|
||||
)),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -95,7 +95,10 @@ impl Command for Save {
|
||||
|
||||
Ok(PipelineData::new(span))
|
||||
}
|
||||
v => Err(ShellError::UnsupportedInput(v.get_type().to_string(), span)),
|
||||
v => Err(ShellError::UnsupportedInput(
|
||||
format!("{:?} not supported", v.get_type()),
|
||||
span,
|
||||
)),
|
||||
}
|
||||
} else {
|
||||
match input.into_value(span) {
|
||||
@ -113,7 +116,10 @@ impl Command for Save {
|
||||
|
||||
Ok(PipelineData::new(span))
|
||||
}
|
||||
v => Err(ShellError::UnsupportedInput(v.get_type().to_string(), span)),
|
||||
v => Err(ShellError::UnsupportedInput(
|
||||
format!("{:?} not supported", v.get_type()),
|
||||
span,
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,8 +46,14 @@ impl Command for ToNuon {
|
||||
|
||||
fn value_to_string(v: &Value, span: Span) -> Result<String, ShellError> {
|
||||
match v {
|
||||
Value::Binary { .. } => Err(ShellError::UnsupportedInput("binary".into(), span)),
|
||||
Value::Block { .. } => Err(ShellError::UnsupportedInput("block".into(), span)),
|
||||
Value::Binary { .. } => Err(ShellError::UnsupportedInput(
|
||||
"binary not supported".into(),
|
||||
span,
|
||||
)),
|
||||
Value::Block { .. } => Err(ShellError::UnsupportedInput(
|
||||
"block not supported".into(),
|
||||
span,
|
||||
)),
|
||||
Value::Bool { val, .. } => {
|
||||
if *val {
|
||||
Ok("$true".to_string())
|
||||
@ -55,11 +61,20 @@ fn value_to_string(v: &Value, span: Span) -> Result<String, ShellError> {
|
||||
Ok("$false".to_string())
|
||||
}
|
||||
}
|
||||
Value::CellPath { .. } => Err(ShellError::UnsupportedInput("cellpath".to_string(), span)),
|
||||
Value::CustomValue { .. } => Err(ShellError::UnsupportedInput("custom".to_string(), span)),
|
||||
Value::CellPath { .. } => Err(ShellError::UnsupportedInput(
|
||||
"cellpath not supported".to_string(),
|
||||
span,
|
||||
)),
|
||||
Value::CustomValue { .. } => Err(ShellError::UnsupportedInput(
|
||||
"custom not supported".to_string(),
|
||||
span,
|
||||
)),
|
||||
Value::Date { val, .. } => Ok(val.to_rfc3339()),
|
||||
Value::Duration { val, .. } => Ok(format!("{}ns", *val)),
|
||||
Value::Error { .. } => Err(ShellError::UnsupportedInput("error".to_string(), span)),
|
||||
Value::Error { .. } => Err(ShellError::UnsupportedInput(
|
||||
"error not supported".to_string(),
|
||||
span,
|
||||
)),
|
||||
Value::Filesize { val, .. } => Ok(format!("{}b", *val)),
|
||||
Value::Float { val, .. } => Ok(format!("{}", *val)),
|
||||
Value::Int { val, .. } => Ok(format!("{}", *val)),
|
||||
|
@ -62,9 +62,12 @@ fn abs_helper(val: Value, head: Span) -> Value {
|
||||
val: val.abs(),
|
||||
span,
|
||||
},
|
||||
_ => Value::Error {
|
||||
other => Value::Error {
|
||||
error: ShellError::UnsupportedInput(
|
||||
String::from("Only numerical values are supported"),
|
||||
format!(
|
||||
"Only numerical values are supported, input type: {:?}",
|
||||
other.get_type()
|
||||
),
|
||||
head,
|
||||
),
|
||||
},
|
||||
|
@ -53,7 +53,10 @@ fn operate(value: Value, head: Span) -> Value {
|
||||
},
|
||||
other => Value::Error {
|
||||
error: ShellError::UnsupportedInput(
|
||||
String::from("Only numerical values are supported"),
|
||||
format!(
|
||||
"Only numerical values are supported, input type: {:?}",
|
||||
other.get_type()
|
||||
),
|
||||
other.span().unwrap_or(head),
|
||||
),
|
||||
},
|
||||
|
@ -53,7 +53,10 @@ fn operate(value: Value, head: Span) -> Value {
|
||||
},
|
||||
other => Value::Error {
|
||||
error: ShellError::UnsupportedInput(
|
||||
String::from("Only numerical values are supported"),
|
||||
format!(
|
||||
"Only numerical values are supported, input type: {:?}",
|
||||
other.get_type()
|
||||
),
|
||||
other.span().unwrap_or(head),
|
||||
),
|
||||
},
|
||||
|
@ -94,7 +94,10 @@ fn operate(value: Value, head: Span, precision: Option<i64>) -> Value {
|
||||
Value::Int { .. } => value,
|
||||
other => Value::Error {
|
||||
error: ShellError::UnsupportedInput(
|
||||
String::from("Only numerical values are supported"),
|
||||
format!(
|
||||
"Only numerical values are supported, input type: {:?}",
|
||||
other.get_type()
|
||||
),
|
||||
other.span().unwrap_or(head),
|
||||
),
|
||||
},
|
||||
|
@ -62,7 +62,10 @@ fn operate(value: Value, head: Span) -> Value {
|
||||
}
|
||||
other => Value::Error {
|
||||
error: ShellError::UnsupportedInput(
|
||||
String::from("Only numerical values are supported"),
|
||||
format!(
|
||||
"Only numerical values are supported, input type: {:?}",
|
||||
other.get_type()
|
||||
),
|
||||
other.span().unwrap_or(head),
|
||||
),
|
||||
},
|
||||
|
@ -152,7 +152,7 @@ pub enum ShellError {
|
||||
|
||||
#[error("Unsupported input")]
|
||||
#[diagnostic(code(nu::shell::unsupported_input), url(docsrs))]
|
||||
UnsupportedInput(String, #[label("{0} not supported")] Span),
|
||||
UnsupportedInput(String, #[label("{0}")] Span),
|
||||
|
||||
#[error("Unable to parse datetime")]
|
||||
#[diagnostic(
|
||||
|
Loading…
Reference in New Issue
Block a user