mirror of
https://github.com/nushell/nushell.git
synced 2025-07-01 07:00:37 +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:
@ -108,15 +108,15 @@ where
|
||||
match rotate_result {
|
||||
Ok(val) => Value::int(val, span),
|
||||
Err(_) => Value::error(
|
||||
ShellError::GenericError(
|
||||
"Rotate left result beyond the range of 64 bit signed number".to_string(),
|
||||
format!(
|
||||
ShellError::GenericError {
|
||||
error: "Rotate left result beyond the range of 64 bit signed number".into(),
|
||||
msg: format!(
|
||||
"{val} of the specified number of bytes rotate left {bits} bits exceed limit"
|
||||
),
|
||||
Some(span),
|
||||
None,
|
||||
Vec::new(),
|
||||
),
|
||||
span: Some(span),
|
||||
help: None,
|
||||
inner: vec![],
|
||||
},
|
||||
span,
|
||||
),
|
||||
}
|
||||
|
@ -112,15 +112,15 @@ where
|
||||
match rotate_result {
|
||||
Ok(val) => Value::int(val, span),
|
||||
Err(_) => Value::error(
|
||||
ShellError::GenericError(
|
||||
"Rotate right result beyond the range of 64 bit signed number".to_string(),
|
||||
format!(
|
||||
ShellError::GenericError {
|
||||
error: "Rotate right result beyond the range of 64 bit signed number".into(),
|
||||
msg: format!(
|
||||
"{val} of the specified number of bytes rotate right {bits} bits exceed limit"
|
||||
),
|
||||
Some(span),
|
||||
None,
|
||||
Vec::new(),
|
||||
),
|
||||
span: Some(span),
|
||||
help: None,
|
||||
inner: vec![],
|
||||
},
|
||||
span,
|
||||
),
|
||||
}
|
||||
|
@ -120,27 +120,27 @@ where
|
||||
match shift_result {
|
||||
Ok(val) => Value::int( val, span ),
|
||||
Err(_) => Value::error(
|
||||
ShellError::GenericError(
|
||||
"Shift left result beyond the range of 64 bit signed number".to_string(),
|
||||
format!(
|
||||
ShellError::GenericError {
|
||||
error:"Shift left result beyond the range of 64 bit signed number".into(),
|
||||
msg: format!(
|
||||
"{val} of the specified number of bytes shift left {bits} bits exceed limit"
|
||||
),
|
||||
Some(span),
|
||||
None,
|
||||
Vec::new(),
|
||||
),
|
||||
span: Some(span),
|
||||
help: None,
|
||||
inner: vec![],
|
||||
},
|
||||
span,
|
||||
),
|
||||
}
|
||||
}
|
||||
None => Value::error(
|
||||
ShellError::GenericError(
|
||||
"Shift left failed".to_string(),
|
||||
format!("{val} shift left {bits} bits failed, you may shift too many bits"),
|
||||
Some(span),
|
||||
None,
|
||||
Vec::new(),
|
||||
),
|
||||
ShellError::GenericError {
|
||||
error: "Shift left failed".into(),
|
||||
msg: format!("{val} shift left {bits} bits failed, you may shift too many bits"),
|
||||
span: Some(span),
|
||||
help: None,
|
||||
inner: vec![],
|
||||
},
|
||||
span,
|
||||
),
|
||||
}
|
||||
|
@ -110,27 +110,27 @@ where
|
||||
match shift_result {
|
||||
Ok(val) => Value::int( val, span ),
|
||||
Err(_) => Value::error(
|
||||
ShellError::GenericError(
|
||||
"Shift right result beyond the range of 64 bit signed number".to_string(),
|
||||
format!(
|
||||
ShellError::GenericError {
|
||||
error: "Shift right result beyond the range of 64 bit signed number".into(),
|
||||
msg: format!(
|
||||
"{val} of the specified number of bytes shift right {bits} bits exceed limit"
|
||||
),
|
||||
Some(span),
|
||||
None,
|
||||
Vec::new(),
|
||||
),
|
||||
span: Some(span),
|
||||
help: None,
|
||||
inner: vec![],
|
||||
},
|
||||
span,
|
||||
),
|
||||
}
|
||||
}
|
||||
None => Value::error(
|
||||
ShellError::GenericError(
|
||||
"Shift right failed".to_string(),
|
||||
format!("{val} shift right {bits} bits failed, you may shift too many bits"),
|
||||
Some(span),
|
||||
None,
|
||||
Vec::new(),
|
||||
),
|
||||
ShellError::GenericError {
|
||||
error: "Shift right failed".into(),
|
||||
msg: format!("{val} shift right {bits} bits failed, you may shift too many bits"),
|
||||
span: Some(span),
|
||||
help: None,
|
||||
inner: vec![],
|
||||
},
|
||||
span,
|
||||
),
|
||||
}
|
||||
|
@ -304,13 +304,13 @@ fn to_html(
|
||||
let color_hm = match color_hm {
|
||||
Ok(c) => c,
|
||||
_ => {
|
||||
return Err(ShellError::GenericError(
|
||||
"Error finding theme name".to_string(),
|
||||
"Error finding theme name".to_string(),
|
||||
Some(theme_span),
|
||||
None,
|
||||
Vec::new(),
|
||||
))
|
||||
return Err(ShellError::GenericError {
|
||||
error: "Error finding theme name".into(),
|
||||
msg: "Error finding theme name".into(),
|
||||
span: Some(theme_span),
|
||||
help: None,
|
||||
inner: vec![],
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -121,22 +121,22 @@ fn action(
|
||||
|
||||
ActionType::Decode => match hex_decode(val.as_ref()) {
|
||||
Ok(decoded_value) => Value::binary(decoded_value, command_span),
|
||||
Err(HexDecodingError::InvalidLength(len)) => Value::error(ShellError::GenericError(
|
||||
"value could not be hex decoded".to_string(),
|
||||
format!("invalid hex input length: {len}. The length should be even"),
|
||||
Some(command_span),
|
||||
None,
|
||||
Vec::new(),
|
||||
),
|
||||
Err(HexDecodingError::InvalidLength(len)) => Value::error(ShellError::GenericError {
|
||||
error: "value could not be hex decoded".into(),
|
||||
msg: format!("invalid hex input length: {len}. The length should be even"),
|
||||
span: Some(command_span),
|
||||
help: None,
|
||||
inner: vec![],
|
||||
},
|
||||
command_span,
|
||||
),
|
||||
Err(HexDecodingError::InvalidDigit(index, digit)) => Value::error(ShellError::GenericError(
|
||||
"value could not be hex decoded".to_string(),
|
||||
format!("invalid hex digit: '{digit}' at index {index}. Only 0-9, A-F, a-f are allowed in hex encoding"),
|
||||
Some(command_span),
|
||||
None,
|
||||
Vec::new(),
|
||||
),
|
||||
Err(HexDecodingError::InvalidDigit(index, digit)) => Value::error(ShellError::GenericError {
|
||||
error: "value could not be hex decoded".into(),
|
||||
msg: format!("invalid hex digit: '{digit}' at index {index}. Only 0-9, A-F, a-f are allowed in hex encoding"),
|
||||
span: Some(command_span),
|
||||
help: None,
|
||||
inner: vec![],
|
||||
},
|
||||
command_span,
|
||||
),
|
||||
},
|
||||
|
Reference in New Issue
Block a user