mirror of
https://github.com/nushell/nushell.git
synced 2025-06-18 16:07:02 +02:00
Replace some PipelineMismatch by OnlySupportsThisInputType by shell error (#15447)
sub-issue of #10698 according to @sholderbach (Description largely edited, since the scope of the PR changed) # Description Context: `ShellError::OnlySupportsThisInputType` was a duplicate of `ShellError::PipelineMismatch` so I - replaced some occurences of PipelineMismatch by OnlySupportsThisInputType For another PR - replace the remaining occurences - removed OnlySupportsThisInputType from nu-protocol # User-Facing Changes The error message will be different -> but consistent # Tests + Formatting OK # After Submitting Nothing required
This commit is contained in:
parent
e82df7c1c9
commit
639f4bd499
@ -159,9 +159,10 @@ where
|
||||
}
|
||||
(Value::Binary { .. }, Value::Int { .. }) | (Value::Int { .. }, Value::Binary { .. }) => {
|
||||
Value::error(
|
||||
ShellError::PipelineMismatch {
|
||||
ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "input, and argument, to be both int or both binary"
|
||||
.to_string(),
|
||||
wrong_type: "int and binary".to_string(),
|
||||
dst_span: rhs.span(),
|
||||
src_span: span,
|
||||
},
|
||||
|
@ -40,6 +40,7 @@ impl Command for SplitCellPath {
|
||||
input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
let head = call.head;
|
||||
let input_type = input.get_type();
|
||||
|
||||
let src_span = match input {
|
||||
// Early return on correct type and empty pipeline
|
||||
@ -54,8 +55,9 @@ impl Command for SplitCellPath {
|
||||
PipelineData::ListStream(stream, ..) => stream.span(),
|
||||
PipelineData::ByteStream(stream, ..) => stream.span(),
|
||||
};
|
||||
Err(ShellError::PipelineMismatch {
|
||||
Err(ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "cell-path".into(),
|
||||
wrong_type: input_type.to_string(),
|
||||
dst_span: head,
|
||||
src_span,
|
||||
})
|
||||
|
@ -42,8 +42,9 @@ pub(crate) fn typecheck_merge(lhs: &Value, rhs: &Value, head: Span) -> Result<()
|
||||
match (lhs.get_type(), rhs.get_type()) {
|
||||
(Type::Record { .. }, Type::Record { .. }) => Ok(()),
|
||||
(_, _) if is_list_of_records(lhs) && is_list_of_records(rhs) => Ok(()),
|
||||
_ => Err(ShellError::PipelineMismatch {
|
||||
other => Err(ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "input and argument to be both record or both table".to_string(),
|
||||
wrong_type: format!("{} and {}", other.0, other.1).to_string(),
|
||||
dst_span: head,
|
||||
src_span: lhs.span(),
|
||||
}),
|
||||
|
@ -174,8 +174,9 @@ impl Command for Move {
|
||||
PipelineData::Value(Value::Record { val, .. }, ..) => {
|
||||
Ok(move_record_columns(&val, &columns, &location, head)?.into_pipeline_data())
|
||||
}
|
||||
_ => Err(ShellError::PipelineMismatch {
|
||||
other => Err(ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "record or table".to_string(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: Span::new(head.start, head.start),
|
||||
}),
|
||||
|
@ -184,9 +184,10 @@ impl Command for Sort {
|
||||
dst_span: value.span(),
|
||||
})
|
||||
}
|
||||
_ => {
|
||||
return Err(ShellError::PipelineMismatch {
|
||||
ref other => {
|
||||
return Err(ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "record or list".to_string(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: call.head,
|
||||
src_span: value.span(),
|
||||
})
|
||||
|
@ -221,14 +221,21 @@ fn join_list(parts: &[Value], head: Span, span: Span, args: &Arguments) -> Value
|
||||
|
||||
Value::list(vals, span)
|
||||
}
|
||||
Err(_) => Value::error(
|
||||
ShellError::PipelineMismatch {
|
||||
Err(ShellError::CantConvert { from_type, .. }) => Value::error(
|
||||
ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "string or record".into(),
|
||||
wrong_type: from_type,
|
||||
dst_span: head,
|
||||
src_span: span,
|
||||
},
|
||||
span,
|
||||
),
|
||||
Err(_) => Value::error(
|
||||
ShellError::NushellFailed {
|
||||
msg: "failed to join path".into(),
|
||||
},
|
||||
span,
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -51,21 +51,11 @@ fn handle_invalid_values(rest: Value, name: Span) -> Value {
|
||||
fn err_from_value(rest: &Value, name: Span) -> ShellError {
|
||||
match rest {
|
||||
Value::Error { error, .. } => *error.clone(),
|
||||
_ => {
|
||||
if rest.is_nothing() {
|
||||
ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "string, record or list".into(),
|
||||
wrong_type: "nothing".into(),
|
||||
dst_span: name,
|
||||
src_span: rest.span(),
|
||||
}
|
||||
} else {
|
||||
ShellError::PipelineMismatch {
|
||||
exp_input_type: "string, row or list".into(),
|
||||
dst_span: name,
|
||||
src_span: rest.span(),
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "string, record or list".into(),
|
||||
wrong_type: rest.get_type().to_string(),
|
||||
dst_span: name,
|
||||
src_span: rest.span(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -181,11 +181,14 @@ fn operate(
|
||||
Value::List { vals, .. } => {
|
||||
let iter = vals.into_iter().map(move |val| {
|
||||
let span = val.span();
|
||||
val.into_string().map_err(|_| ShellError::PipelineMismatch {
|
||||
exp_input_type: "string".into(),
|
||||
dst_span: head,
|
||||
src_span: span,
|
||||
})
|
||||
let type_ = val.get_type();
|
||||
val.into_string()
|
||||
.map_err(|_| ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "string".into(),
|
||||
wrong_type: type_.to_string(),
|
||||
dst_span: head,
|
||||
src_span: span,
|
||||
})
|
||||
});
|
||||
|
||||
let iter = ParseIter {
|
||||
@ -199,8 +202,9 @@ fn operate(
|
||||
|
||||
Ok(ListStream::new(iter, head, Signals::empty()).into())
|
||||
}
|
||||
value => Err(ShellError::PipelineMismatch {
|
||||
value => Err(ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "string".into(),
|
||||
wrong_type: value.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: value.span(),
|
||||
}),
|
||||
|
@ -153,8 +153,9 @@ fn split_chars_helper(v: &Value, name: Span, graphemes: bool) -> Value {
|
||||
)
|
||||
} else {
|
||||
Value::error(
|
||||
ShellError::PipelineMismatch {
|
||||
ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "string".into(),
|
||||
wrong_type: v.get_type().to_string(),
|
||||
dst_span: name,
|
||||
src_span: v_span,
|
||||
},
|
||||
|
@ -255,8 +255,9 @@ fn split_column_helper(
|
||||
v => {
|
||||
let span = v.span();
|
||||
vec![Value::error(
|
||||
ShellError::PipelineMismatch {
|
||||
ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "string".into(),
|
||||
wrong_type: v.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: span,
|
||||
},
|
||||
|
@ -219,8 +219,9 @@ fn split_row_helper(v: &Value, regex: &Regex, max_split: Option<usize>, name: Sp
|
||||
}
|
||||
} else {
|
||||
vec![Value::error(
|
||||
ShellError::PipelineMismatch {
|
||||
ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "string".into(),
|
||||
wrong_type: v.get_type().to_string(),
|
||||
dst_span: name,
|
||||
src_span: v_span,
|
||||
},
|
||||
|
@ -226,8 +226,9 @@ fn split_words_helper(v: &Value, word_length: Option<usize>, span: Span, graphem
|
||||
Value::list(words, v_span)
|
||||
} else {
|
||||
Value::error(
|
||||
ShellError::PipelineMismatch {
|
||||
ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "string".into(),
|
||||
wrong_type: v.get_type().to_string(),
|
||||
dst_span: span,
|
||||
src_span: v_span,
|
||||
},
|
||||
|
@ -237,14 +237,16 @@ fn run(
|
||||
input.map(
|
||||
move |v| {
|
||||
let value_span = v.span();
|
||||
let type_ = v.get_type();
|
||||
match v.coerce_into_string() {
|
||||
Ok(s) => {
|
||||
let contents = if is_path { s.replace('\\', "\\\\") } else { s };
|
||||
str_expand(&contents, span, value_span)
|
||||
}
|
||||
Err(_) => Value::error(
|
||||
ShellError::PipelineMismatch {
|
||||
ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "string".into(),
|
||||
wrong_type: type_.to_string(),
|
||||
dst_span: span,
|
||||
src_span: value_span,
|
||||
},
|
||||
|
@ -108,6 +108,7 @@ fn stats(
|
||||
input.map(
|
||||
move |v| {
|
||||
let value_span = v.span();
|
||||
let type_ = v.get_type();
|
||||
// First, obtain the span. If this fails, propagate the error that results.
|
||||
if let Value::Error { error, .. } = v {
|
||||
return Value::error(*error, span);
|
||||
@ -116,8 +117,9 @@ fn stats(
|
||||
match v.coerce_into_string() {
|
||||
Ok(s) => counter(&s, span),
|
||||
Err(_) => Value::error(
|
||||
ShellError::PipelineMismatch {
|
||||
ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "string".into(),
|
||||
wrong_type: type_.to_string(),
|
||||
dst_span: span,
|
||||
src_span: value_span,
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user