mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 03:34:58 +02:00
Convert Shellerror::GenericError
to named fields (#11230)
# Description Replace `.to_string()` used in `GenericError` with `.into()` as `.into()` seems more popular Replace `Vec::new()` used in `GenericError` with `vec![]` as `vec![]` seems more popular (There are so, so many)
This commit is contained in:
@ -155,13 +155,13 @@ used as the next argument to the closure, otherwise generation stops.
|
||||
} else if k.eq_ignore_ascii_case("next") {
|
||||
next = Some(v);
|
||||
} else {
|
||||
let error = ShellError::GenericError(
|
||||
"Invalid block return".to_string(),
|
||||
format!("Unexpected record key '{}'", k),
|
||||
Some(span),
|
||||
None,
|
||||
Vec::new(),
|
||||
);
|
||||
let error = ShellError::GenericError {
|
||||
error: "Invalid block return".into(),
|
||||
msg: format!("Unexpected record key '{}'", k),
|
||||
span: Some(span),
|
||||
help: None,
|
||||
inner: vec![],
|
||||
};
|
||||
err = Some(Value::error(error, block_span));
|
||||
break;
|
||||
}
|
||||
@ -176,13 +176,13 @@ used as the next argument to the closure, otherwise generation stops.
|
||||
|
||||
// some other value -> error and stop
|
||||
_ => {
|
||||
let error = ShellError::GenericError(
|
||||
"Invalid block return".to_string(),
|
||||
format!("Expected record, found {}", value.get_type()),
|
||||
Some(span),
|
||||
None,
|
||||
Vec::new(),
|
||||
);
|
||||
let error = ShellError::GenericError {
|
||||
error: "Invalid block return".into(),
|
||||
msg: format!("Expected record, found {}", value.get_type()),
|
||||
span: Some(span),
|
||||
help: None,
|
||||
inner: vec![],
|
||||
};
|
||||
|
||||
(Some(Value::error(error, block_span)), None)
|
||||
}
|
||||
@ -191,13 +191,13 @@ used as the next argument to the closure, otherwise generation stops.
|
||||
|
||||
Ok(other) => {
|
||||
let val = other.into_value(block_span);
|
||||
let error = ShellError::GenericError(
|
||||
"Invalid block return".to_string(),
|
||||
format!("Expected record, found {}", val.get_type()),
|
||||
Some(val.span()),
|
||||
None,
|
||||
Vec::new(),
|
||||
);
|
||||
let error = ShellError::GenericError {
|
||||
error: "Invalid block return".into(),
|
||||
msg: format!("Expected record, found {}", val.get_type()),
|
||||
span: Some(val.span()),
|
||||
help: None,
|
||||
inner: vec![],
|
||||
};
|
||||
|
||||
(Some(Value::error(error, block_span)), None)
|
||||
}
|
||||
|
@ -101,13 +101,13 @@ fn seq(
|
||||
let contains_decimals = rest_nums_check.is_err();
|
||||
|
||||
if rest_nums.is_empty() {
|
||||
return Err(ShellError::GenericError(
|
||||
"seq requires some parameters".into(),
|
||||
"needs parameter".into(),
|
||||
Some(call.head),
|
||||
None,
|
||||
Vec::new(),
|
||||
));
|
||||
return Err(ShellError::GenericError {
|
||||
error: "seq requires some parameters".into(),
|
||||
msg: "needs parameter".into(),
|
||||
span: Some(call.head),
|
||||
help: None,
|
||||
inner: vec![],
|
||||
});
|
||||
}
|
||||
|
||||
let rest_nums: Vec<f64> = rest_nums.iter().map(|n| n.item).collect();
|
||||
|
@ -82,23 +82,23 @@ fn seq_char(
|
||||
let end: Spanned<String> = call.req(engine_state, stack, 1)?;
|
||||
|
||||
if !is_single_character(&start.item) {
|
||||
return Err(ShellError::GenericError(
|
||||
"seq char only accepts individual ASCII characters as parameters".into(),
|
||||
"should be 1 character long".into(),
|
||||
Some(start.span),
|
||||
None,
|
||||
Vec::new(),
|
||||
));
|
||||
return Err(ShellError::GenericError {
|
||||
error: "seq char only accepts individual ASCII characters as parameters".into(),
|
||||
msg: "should be 1 character long".into(),
|
||||
span: Some(start.span),
|
||||
help: None,
|
||||
inner: vec![],
|
||||
});
|
||||
}
|
||||
|
||||
if !is_single_character(&end.item) {
|
||||
return Err(ShellError::GenericError(
|
||||
"seq char only accepts individual ASCII characters as parameters".into(),
|
||||
"should be 1 character long".into(),
|
||||
Some(end.span),
|
||||
None,
|
||||
Vec::new(),
|
||||
));
|
||||
return Err(ShellError::GenericError {
|
||||
error: "seq char only accepts individual ASCII characters as parameters".into(),
|
||||
msg: "should be 1 character long".into(),
|
||||
span: Some(end.span),
|
||||
help: None,
|
||||
inner: vec![],
|
||||
});
|
||||
}
|
||||
|
||||
let start = start
|
||||
|
@ -194,26 +194,26 @@ pub fn run_seq_dates(
|
||||
let mut step_size: i64 = increment.as_i64()?;
|
||||
|
||||
if step_size == 0 {
|
||||
return Err(ShellError::GenericError(
|
||||
"increment cannot be 0".to_string(),
|
||||
"increment cannot be 0".to_string(),
|
||||
Some(increment.span()),
|
||||
None,
|
||||
Vec::new(),
|
||||
));
|
||||
return Err(ShellError::GenericError {
|
||||
error: "increment cannot be 0".into(),
|
||||
msg: "increment cannot be 0".into(),
|
||||
span: Some(increment.span()),
|
||||
help: None,
|
||||
inner: vec![],
|
||||
});
|
||||
}
|
||||
|
||||
let in_format = match input_format {
|
||||
Some(i) => match i.as_string() {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
return Err(ShellError::GenericError(
|
||||
e.to_string(),
|
||||
"".to_string(),
|
||||
None,
|
||||
Some("error with input_format as_string".to_string()),
|
||||
Vec::new(),
|
||||
));
|
||||
return Err(ShellError::GenericError {
|
||||
error: e.to_string(),
|
||||
msg: "".into(),
|
||||
span: None,
|
||||
help: Some("error with input_format as_string".into()),
|
||||
inner: vec![],
|
||||
});
|
||||
}
|
||||
},
|
||||
_ => "%Y-%m-%d".to_string(),
|
||||
@ -223,13 +223,13 @@ pub fn run_seq_dates(
|
||||
Some(i) => match i.as_string() {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
return Err(ShellError::GenericError(
|
||||
e.to_string(),
|
||||
"".to_string(),
|
||||
None,
|
||||
Some("error with output_format as_string".to_string()),
|
||||
Vec::new(),
|
||||
));
|
||||
return Err(ShellError::GenericError {
|
||||
error: e.to_string(),
|
||||
msg: "".into(),
|
||||
span: None,
|
||||
help: Some("error with output_format as_string".into()),
|
||||
inner: vec![],
|
||||
});
|
||||
}
|
||||
},
|
||||
_ => "%Y-%m-%d".to_string(),
|
||||
@ -239,13 +239,13 @@ pub fn run_seq_dates(
|
||||
Some(d) => match parse_date_string(&d, &in_format) {
|
||||
Ok(nd) => nd,
|
||||
Err(e) => {
|
||||
return Err(ShellError::GenericError(
|
||||
e.to_string(),
|
||||
"Failed to parse date".to_string(),
|
||||
Some(call_span),
|
||||
None,
|
||||
Vec::new(),
|
||||
))
|
||||
return Err(ShellError::GenericError {
|
||||
error: e.to_string(),
|
||||
msg: "Failed to parse date".into(),
|
||||
span: Some(call_span),
|
||||
help: None,
|
||||
inner: vec![],
|
||||
})
|
||||
}
|
||||
},
|
||||
_ => today,
|
||||
@ -255,13 +255,13 @@ pub fn run_seq_dates(
|
||||
Some(d) => match parse_date_string(&d, &in_format) {
|
||||
Ok(nd) => nd,
|
||||
Err(e) => {
|
||||
return Err(ShellError::GenericError(
|
||||
e.to_string(),
|
||||
"Failed to parse date".to_string(),
|
||||
Some(call_span),
|
||||
None,
|
||||
Vec::new(),
|
||||
))
|
||||
return Err(ShellError::GenericError {
|
||||
error: e.to_string(),
|
||||
msg: "Failed to parse date".into(),
|
||||
span: Some(call_span),
|
||||
help: None,
|
||||
inner: vec![],
|
||||
})
|
||||
}
|
||||
},
|
||||
_ => today,
|
||||
@ -282,13 +282,13 @@ pub fn run_seq_dates(
|
||||
end_date = match start_date.checked_add_signed(Duration::days(days_to_output)) {
|
||||
Some(date) => date,
|
||||
None => {
|
||||
return Err(ShellError::GenericError(
|
||||
"int value too large".to_string(),
|
||||
"int value too large".to_string(),
|
||||
Some(call_span),
|
||||
None,
|
||||
Vec::new(),
|
||||
));
|
||||
return Err(ShellError::GenericError {
|
||||
error: "int value too large".into(),
|
||||
msg: "int value too large".into(),
|
||||
span: Some(call_span),
|
||||
help: None,
|
||||
inner: vec![],
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -304,13 +304,13 @@ pub fn run_seq_dates(
|
||||
|
||||
let mut next = start_date;
|
||||
if is_out_of_range(next) {
|
||||
return Err(ShellError::GenericError(
|
||||
"date is out of range".to_string(),
|
||||
"date is out of range".to_string(),
|
||||
Some(call_span),
|
||||
None,
|
||||
Vec::new(),
|
||||
));
|
||||
return Err(ShellError::GenericError {
|
||||
error: "date is out of range".into(),
|
||||
msg: "date is out of range".into(),
|
||||
span: Some(call_span),
|
||||
help: None,
|
||||
inner: vec![],
|
||||
});
|
||||
}
|
||||
|
||||
let mut ret = vec![];
|
||||
|
Reference in New Issue
Block a user