mirror of
https://github.com/nushell/nushell.git
synced 2025-04-15 08:48:19 +02: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))
|
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))
|
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 {
|
} else {
|
||||||
match input.into_value(span) {
|
match input.into_value(span) {
|
||||||
@ -113,7 +116,10 @@ impl Command for Save {
|
|||||||
|
|
||||||
Ok(PipelineData::new(span))
|
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> {
|
fn value_to_string(v: &Value, span: Span) -> Result<String, ShellError> {
|
||||||
match v {
|
match v {
|
||||||
Value::Binary { .. } => Err(ShellError::UnsupportedInput("binary".into(), span)),
|
Value::Binary { .. } => Err(ShellError::UnsupportedInput(
|
||||||
Value::Block { .. } => Err(ShellError::UnsupportedInput("block".into(), span)),
|
"binary not supported".into(),
|
||||||
|
span,
|
||||||
|
)),
|
||||||
|
Value::Block { .. } => Err(ShellError::UnsupportedInput(
|
||||||
|
"block not supported".into(),
|
||||||
|
span,
|
||||||
|
)),
|
||||||
Value::Bool { val, .. } => {
|
Value::Bool { val, .. } => {
|
||||||
if *val {
|
if *val {
|
||||||
Ok("$true".to_string())
|
Ok("$true".to_string())
|
||||||
@ -55,11 +61,20 @@ fn value_to_string(v: &Value, span: Span) -> Result<String, ShellError> {
|
|||||||
Ok("$false".to_string())
|
Ok("$false".to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Value::CellPath { .. } => Err(ShellError::UnsupportedInput("cellpath".to_string(), span)),
|
Value::CellPath { .. } => Err(ShellError::UnsupportedInput(
|
||||||
Value::CustomValue { .. } => Err(ShellError::UnsupportedInput("custom".to_string(), span)),
|
"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::Date { val, .. } => Ok(val.to_rfc3339()),
|
||||||
Value::Duration { val, .. } => Ok(format!("{}ns", *val)),
|
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::Filesize { val, .. } => Ok(format!("{}b", *val)),
|
||||||
Value::Float { val, .. } => Ok(format!("{}", *val)),
|
Value::Float { val, .. } => Ok(format!("{}", *val)),
|
||||||
Value::Int { 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(),
|
val: val.abs(),
|
||||||
span,
|
span,
|
||||||
},
|
},
|
||||||
_ => Value::Error {
|
other => Value::Error {
|
||||||
error: ShellError::UnsupportedInput(
|
error: ShellError::UnsupportedInput(
|
||||||
String::from("Only numerical values are supported"),
|
format!(
|
||||||
|
"Only numerical values are supported, input type: {:?}",
|
||||||
|
other.get_type()
|
||||||
|
),
|
||||||
head,
|
head,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
@ -53,7 +53,10 @@ fn operate(value: Value, head: Span) -> Value {
|
|||||||
},
|
},
|
||||||
other => Value::Error {
|
other => Value::Error {
|
||||||
error: ShellError::UnsupportedInput(
|
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),
|
other.span().unwrap_or(head),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
@ -53,7 +53,10 @@ fn operate(value: Value, head: Span) -> Value {
|
|||||||
},
|
},
|
||||||
other => Value::Error {
|
other => Value::Error {
|
||||||
error: ShellError::UnsupportedInput(
|
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),
|
other.span().unwrap_or(head),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
@ -94,7 +94,10 @@ fn operate(value: Value, head: Span, precision: Option<i64>) -> Value {
|
|||||||
Value::Int { .. } => value,
|
Value::Int { .. } => value,
|
||||||
other => Value::Error {
|
other => Value::Error {
|
||||||
error: ShellError::UnsupportedInput(
|
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),
|
other.span().unwrap_or(head),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
@ -62,7 +62,10 @@ fn operate(value: Value, head: Span) -> Value {
|
|||||||
}
|
}
|
||||||
other => Value::Error {
|
other => Value::Error {
|
||||||
error: ShellError::UnsupportedInput(
|
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),
|
other.span().unwrap_or(head),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
@ -152,7 +152,7 @@ pub enum ShellError {
|
|||||||
|
|
||||||
#[error("Unsupported input")]
|
#[error("Unsupported input")]
|
||||||
#[diagnostic(code(nu::shell::unsupported_input), url(docsrs))]
|
#[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")]
|
#[error("Unable to parse datetime")]
|
||||||
#[diagnostic(
|
#[diagnostic(
|
||||||
|
Loading…
Reference in New Issue
Block a user