removed unwraps (#430)

This commit is contained in:
Fernando Herrera
2021-12-04 12:38:21 +00:00
committed by GitHub
parent eed22605ef
commit 8a06ea133b
24 changed files with 233 additions and 159 deletions

View File

@ -114,11 +114,13 @@ fn into_int(
None => 10,
};
if !(2..=36).contains(&radix) {
return Err(ShellError::UnsupportedInput(
"Radix must lie in the range [2, 36]".to_string(),
options.radix.unwrap().span().unwrap(),
));
if let Some(val) = &options.radix {
if !(2..=36).contains(&radix) {
return Err(ShellError::UnsupportedInput(
"Radix must lie in the range [2, 36]".to_string(),
val.span()?,
));
}
}
input.map(

View File

@ -139,11 +139,13 @@ fn string_helper(
let column_paths: Vec<CellPath> = call.rest(engine_state, stack, 0)?;
let config = stack.get_config()?;
if decimals && decimals_value.is_some() && decimals_value.unwrap().is_negative() {
return Err(ShellError::UnsupportedInput(
"Cannot accept negative integers for decimals arguments".to_string(),
head,
));
if let Some(decimal_val) = decimals_value {
if decimals && decimal_val.is_negative() {
return Err(ShellError::UnsupportedInput(
"Cannot accept negative integers for decimals arguments".to_string(),
head,
));
}
}
input.map(
@ -192,7 +194,7 @@ pub fn action(
}
Value::Float { val, .. } => {
if decimals {
let decimal_value = digits.unwrap() as usize;
let decimal_value = digits.unwrap_or(2) as usize;
Value::String {
val: format!("{:.*}", decimal_value, val),
span,