mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 19:37:45 +02:00
Convert ShellError::UnsupportedInput to named fields (#10971)
# Description This is easy to do with rust-analyzer, but I didn't want to just pump these all out without feedback. Part of #10700 # User-Facing Changes None # Tests + Formatting - 🟢 `toolkit fmt` - 🟢 `toolkit clippy` - 🟢 `toolkit test` - 🟢 `toolkit test stdlib` # After Submitting N/A --------- Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
This commit is contained in:
@ -60,12 +60,12 @@ impl Command for BitsNot {
|
||||
let bytes_len = get_number_bytes(number_bytes.as_ref());
|
||||
if let NumberBytes::Invalid = bytes_len {
|
||||
if let Some(val) = number_bytes {
|
||||
return Err(ShellError::UnsupportedInput(
|
||||
"Only 1, 2, 4, 8, or 'auto' bytes are supported as word sizes".to_string(),
|
||||
"value originates from here".to_string(),
|
||||
head,
|
||||
val.span,
|
||||
));
|
||||
return Err(ShellError::UnsupportedInput {
|
||||
msg: "Only 1, 2, 4, 8, or 'auto' bytes are supported as word sizes".to_string(),
|
||||
input: "value originates from here".to_string(),
|
||||
msg_span: head,
|
||||
input_span: val.span,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,12 +63,12 @@ impl Command for BitsRol {
|
||||
let bytes_len = get_number_bytes(number_bytes.as_ref());
|
||||
if let NumberBytes::Invalid = bytes_len {
|
||||
if let Some(val) = number_bytes {
|
||||
return Err(ShellError::UnsupportedInput(
|
||||
"Only 1, 2, 4, 8, or 'auto' bytes are supported as word sizes".to_string(),
|
||||
"value originates from here".to_string(),
|
||||
head,
|
||||
val.span,
|
||||
));
|
||||
return Err(ShellError::UnsupportedInput {
|
||||
msg: "Only 1, 2, 4, 8, or 'auto' bytes are supported as word sizes".to_string(),
|
||||
input: "value originates from here".to_string(),
|
||||
msg_span: head,
|
||||
input_span: val.span,
|
||||
});
|
||||
}
|
||||
}
|
||||
// This doesn't match explicit nulls
|
||||
|
@ -63,12 +63,12 @@ impl Command for BitsRor {
|
||||
let bytes_len = get_number_bytes(number_bytes.as_ref());
|
||||
if let NumberBytes::Invalid = bytes_len {
|
||||
if let Some(val) = number_bytes {
|
||||
return Err(ShellError::UnsupportedInput(
|
||||
"Only 1, 2, 4, 8, or 'auto' bytes are supported as word sizes".to_string(),
|
||||
"value originates from here".to_string(),
|
||||
head,
|
||||
val.span,
|
||||
));
|
||||
return Err(ShellError::UnsupportedInput {
|
||||
msg: "Only 1, 2, 4, 8, or 'auto' bytes are supported as word sizes".to_string(),
|
||||
input: "value originates from here".to_string(),
|
||||
msg_span: head,
|
||||
input_span: val.span,
|
||||
});
|
||||
}
|
||||
}
|
||||
// This doesn't match explicit nulls
|
||||
|
@ -63,12 +63,12 @@ impl Command for BitsShl {
|
||||
let bytes_len = get_number_bytes(number_bytes.as_ref());
|
||||
if let NumberBytes::Invalid = bytes_len {
|
||||
if let Some(val) = number_bytes {
|
||||
return Err(ShellError::UnsupportedInput(
|
||||
"Only 1, 2, 4, 8, or 'auto' bytes are supported as word sizes".to_string(),
|
||||
"value originates from here".to_string(),
|
||||
head,
|
||||
val.span,
|
||||
));
|
||||
return Err(ShellError::UnsupportedInput {
|
||||
msg: "Only 1, 2, 4, 8, or 'auto' bytes are supported as word sizes".to_string(),
|
||||
input: "value originates from here".to_string(),
|
||||
msg_span: head,
|
||||
input_span: val.span,
|
||||
});
|
||||
}
|
||||
}
|
||||
// This doesn't match explicit nulls
|
||||
|
@ -63,12 +63,12 @@ impl Command for BitsShr {
|
||||
let bytes_len = get_number_bytes(number_bytes.as_ref());
|
||||
if let NumberBytes::Invalid = bytes_len {
|
||||
if let Some(val) = number_bytes {
|
||||
return Err(ShellError::UnsupportedInput(
|
||||
"Only 1, 2, 4, 8, or 'auto' bytes are supported as word sizes".to_string(),
|
||||
"value originates from here".to_string(),
|
||||
head,
|
||||
val.span,
|
||||
));
|
||||
return Err(ShellError::UnsupportedInput {
|
||||
msg: "Only 1, 2, 4, 8, or 'auto' bytes are supported as word sizes".to_string(),
|
||||
input: "value originates from here".to_string(),
|
||||
msg_span: head,
|
||||
input_span: val.span,
|
||||
});
|
||||
}
|
||||
}
|
||||
// This doesn't match explicit nulls
|
||||
|
@ -200,13 +200,12 @@ pub fn rotate(
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return Err(ShellError::UnsupportedInput(
|
||||
"list input is empty".to_string(),
|
||||
"value originates from here".into(),
|
||||
call.head,
|
||||
// TODO: Maybe make all Pipelines have spans, so that this doesn't need to be unwrapped.
|
||||
span.unwrap_or(call.head),
|
||||
));
|
||||
return Err(ShellError::UnsupportedInput {
|
||||
msg: "list input is empty".to_string(),
|
||||
input: "value originates from here".into(),
|
||||
msg_span: call.head,
|
||||
input_span: span.unwrap_or(call.head),
|
||||
});
|
||||
}
|
||||
|
||||
let total_columns = &old_column_names.len();
|
||||
|
@ -61,12 +61,12 @@ fn from_url(input: PipelineData, head: Span) -> Result<PipelineData, ShellError>
|
||||
|
||||
Ok(PipelineData::Value(Value::record(record, head), metadata))
|
||||
}
|
||||
_ => Err(ShellError::UnsupportedInput(
|
||||
"String not compatible with URL encoding".to_string(),
|
||||
"value originates from here".into(),
|
||||
head,
|
||||
span,
|
||||
)),
|
||||
_ => Err(ShellError::UnsupportedInput {
|
||||
msg: "String not compatible with URL encoding".to_string(),
|
||||
input: "value originates from here".into(),
|
||||
msg_span: head,
|
||||
input_span: span,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,12 +84,13 @@ fn operate(value: Value, head: Span, use_degrees: bool) -> Value {
|
||||
Value::float(val, span)
|
||||
} else {
|
||||
Value::error(
|
||||
ShellError::UnsupportedInput(
|
||||
"'arccos' undefined for values outside the closed interval [-1, 1].".into(),
|
||||
"value originates from here".into(),
|
||||
head,
|
||||
span,
|
||||
),
|
||||
ShellError::UnsupportedInput {
|
||||
msg: "'arccos' undefined for values outside the closed interval [-1, 1]."
|
||||
.into(),
|
||||
input: "value originates from here".into(),
|
||||
msg_span: head,
|
||||
input_span: span,
|
||||
},
|
||||
span,
|
||||
)
|
||||
}
|
||||
|
@ -74,12 +74,12 @@ fn operate(value: Value, head: Span) -> Value {
|
||||
Value::float(val, span)
|
||||
} else {
|
||||
Value::error(
|
||||
ShellError::UnsupportedInput(
|
||||
"'arccosh' undefined for values below 1.".into(),
|
||||
"value originates from here".into(),
|
||||
head,
|
||||
span,
|
||||
),
|
||||
ShellError::UnsupportedInput {
|
||||
msg: "'arccosh' undefined for values below 1.".into(),
|
||||
input: "value originates from here".into(),
|
||||
msg_span: head,
|
||||
input_span: span,
|
||||
},
|
||||
span,
|
||||
)
|
||||
}
|
||||
|
@ -85,12 +85,13 @@ fn operate(value: Value, head: Span, use_degrees: bool) -> Value {
|
||||
Value::float(val, span)
|
||||
} else {
|
||||
Value::error(
|
||||
ShellError::UnsupportedInput(
|
||||
"'arcsin' undefined for values outside the closed interval [-1, 1].".into(),
|
||||
"value originates from here".into(),
|
||||
head,
|
||||
span,
|
||||
),
|
||||
ShellError::UnsupportedInput {
|
||||
msg: "'arcsin' undefined for values outside the closed interval [-1, 1]."
|
||||
.into(),
|
||||
input: "value originates from here".into(),
|
||||
msg_span: head,
|
||||
input_span: span,
|
||||
},
|
||||
span,
|
||||
)
|
||||
}
|
||||
|
@ -74,12 +74,13 @@ fn operate(value: Value, head: Span) -> Value {
|
||||
Value::float(val, span)
|
||||
} else {
|
||||
Value::error(
|
||||
ShellError::UnsupportedInput(
|
||||
"'arctanh' undefined for values outside the open interval (-1, 1).".into(),
|
||||
"value originates from here".into(),
|
||||
head,
|
||||
span,
|
||||
),
|
||||
ShellError::UnsupportedInput {
|
||||
msg: "'arctanh' undefined for values outside the open interval (-1, 1)."
|
||||
.into(),
|
||||
input: "value originates from here".into(),
|
||||
msg_span: head,
|
||||
input_span: span,
|
||||
},
|
||||
head,
|
||||
)
|
||||
}
|
||||
|
@ -74,12 +74,12 @@ fn operate(value: Value, head: Span) -> Value {
|
||||
Value::float(val, span)
|
||||
} else {
|
||||
Value::error(
|
||||
ShellError::UnsupportedInput(
|
||||
"'ln' undefined for values outside the open interval (0, Inf).".into(),
|
||||
"value originates from here".into(),
|
||||
head,
|
||||
span,
|
||||
),
|
||||
ShellError::UnsupportedInput {
|
||||
msg: "'ln' undefined for values outside the open interval (0, Inf).".into(),
|
||||
input: "value originates from here".into(),
|
||||
msg_span: head,
|
||||
input_span: span,
|
||||
},
|
||||
span,
|
||||
)
|
||||
}
|
||||
|
@ -108,26 +108,14 @@ fn action(
|
||||
Value::Binary { val, .. } => match hex_config.action_type {
|
||||
ActionType::Encode => Value::string(hex_encode(val.as_ref()), command_span),
|
||||
ActionType::Decode => Value::error(
|
||||
ShellError::UnsupportedInput(
|
||||
"Binary data can only be encoded".to_string(),
|
||||
"value originates from here".into(),
|
||||
command_span,
|
||||
// This line requires the Value::Error {} match above.
|
||||
input.span(),
|
||||
),
|
||||
ShellError::UnsupportedInput { msg: "Binary data can only be encoded".to_string(), input: "value originates from here".into(), msg_span: command_span, input_span: input.span() },
|
||||
command_span,
|
||||
),
|
||||
},
|
||||
Value::String { val, .. } => {
|
||||
match hex_config.action_type {
|
||||
ActionType::Encode => Value::error(
|
||||
ShellError::UnsupportedInput(
|
||||
"String value can only be decoded".to_string(),
|
||||
"value originates from here".into(),
|
||||
command_span,
|
||||
// This line requires the Value::Error {} match above.
|
||||
input.span(),
|
||||
),
|
||||
ShellError::UnsupportedInput { msg: "String value can only be decoded".to_string(), input: "value originates from here".into(), msg_span: command_span, input_span: input.span() },
|
||||
command_span,
|
||||
),
|
||||
|
||||
|
Reference in New Issue
Block a user