Skip to content

Commit

Permalink
Use miette::bail! more often
Browse files Browse the repository at this point in the history
  • Loading branch information
Hofer-Julian committed Oct 17, 2024
1 parent ee95b16 commit 2325289
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions crates/deno_task_shell/src/shell/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ impl ArithmeticResult {
if sum.is_finite() {
ArithmeticValue::Float(sum)
} else {
return Err(miette::miette!("Float overflow: {} + {}", lhs, rhs));
miette::bail!("Float overflow: {} + {}", lhs, rhs);
}
}
(ArithmeticValue::Integer(lhs), ArithmeticValue::Float(rhs))
Expand All @@ -637,7 +637,7 @@ impl ArithmeticResult {
if sum.is_finite() {
ArithmeticValue::Float(sum)
} else {
return Err(miette::miette!("Float overflow: {} + {}", lhs, rhs));
miette::bail!("Float overflow: {} + {}", lhs, rhs);
}
}
};
Expand Down Expand Up @@ -667,23 +667,23 @@ impl ArithmeticResult {
if diff.is_finite() {
ArithmeticValue::Float(diff)
} else {
return Err(miette::miette!("Float overflow: {} - {}", lhs, rhs));
miette::bail!("Float overflow: {} - {}", lhs, rhs);
}
}
(ArithmeticValue::Integer(lhs), ArithmeticValue::Float(rhs)) => {
let diff = *lhs as f64 - rhs;
if diff.is_finite() {
ArithmeticValue::Float(diff)
} else {
return Err(miette::miette!("Float overflow: {} - {}", lhs, rhs));
miette::bail!("Float overflow: {} - {}", lhs, rhs);
}
}
(ArithmeticValue::Float(lhs), ArithmeticValue::Integer(rhs)) => {
let diff = lhs - *rhs as f64;
if diff.is_finite() {
ArithmeticValue::Float(diff)
} else {
return Err(miette::miette!("Float overflow: {} - {}", lhs, rhs));
miette::bail!("Float overflow: {} - {}", lhs, rhs);
}
}
};
Expand Down Expand Up @@ -713,7 +713,7 @@ impl ArithmeticResult {
if product.is_finite() {
ArithmeticValue::Float(product)
} else {
return Err(miette::miette!("Float overflow: {} * {}", lhs, rhs));
miette::bail!("Float overflow: {} * {}", lhs, rhs);
}
}
(ArithmeticValue::Integer(lhs), ArithmeticValue::Float(rhs))
Expand All @@ -722,7 +722,7 @@ impl ArithmeticResult {
if product.is_finite() {
ArithmeticValue::Float(product)
} else {
return Err(miette::miette!("Float overflow: {} * {}", lhs, rhs));
miette::bail!("Float overflow: {} * {}", lhs, rhs);
}
}
};
Expand All @@ -743,7 +743,7 @@ impl ArithmeticResult {
let result = match (&self.value, &other.value) {
(ArithmeticValue::Integer(lhs), ArithmeticValue::Integer(rhs)) => {
if *rhs == 0 {
return Err(miette::miette!("Division by zero: {} / {}", lhs, rhs));
miette::bail!("Division by zero: {} / {}", lhs, rhs);
}
lhs
.checked_div(*rhs)
Expand All @@ -754,35 +754,35 @@ impl ArithmeticResult {
}
(ArithmeticValue::Float(lhs), ArithmeticValue::Float(rhs)) => {
if *rhs == 0.0 {
return Err(miette::miette!("Division by zero: {} / {}", lhs, rhs));
miette::bail!("Division by zero: {} / {}", lhs, rhs);
}
let quotient = lhs / rhs;
if quotient.is_finite() {
ArithmeticValue::Float(quotient)
} else {
return Err(miette::miette!("Float overflow: {} / {}", lhs, rhs));
miette::bail!("Float overflow: {} / {}", lhs, rhs);
}
}
(ArithmeticValue::Integer(lhs), ArithmeticValue::Float(rhs)) => {
if *rhs == 0.0 {
return Err(miette::miette!("Division by zero: {} / {}", lhs, rhs));
miette::bail!("Division by zero: {} / {}", lhs, rhs);
}
let quotient = *lhs as f64 / rhs;
if quotient.is_finite() {
ArithmeticValue::Float(quotient)
} else {
return Err(miette::miette!("Float overflow: {} / {}", lhs, rhs));
miette::bail!("Float overflow: {} / {}", lhs, rhs);
}
}
(ArithmeticValue::Float(lhs), ArithmeticValue::Integer(rhs)) => {
if *rhs == 0 {
return Err(miette::miette!("Division by zero: {} / {}", lhs, rhs));
miette::bail!("Division by zero: {} / {}", lhs, rhs);
}
let quotient = lhs / *rhs as f64;
if quotient.is_finite() {
ArithmeticValue::Float(quotient)
} else {
return Err(miette::miette!("Float overflow: {} / {}", lhs, rhs));
miette::bail!("Float overflow: {} / {}", lhs, rhs);
}
}
};
Expand All @@ -803,7 +803,7 @@ impl ArithmeticResult {
let result = match (&self.value, &other.value) {
(ArithmeticValue::Integer(lhs), ArithmeticValue::Integer(rhs)) => {
if *rhs == 0 {
return Err(miette::miette!("Modulo by zero: {} % {}", lhs, rhs));
miette::bail!("Modulo by zero: {} % {}", lhs, rhs);
}
lhs
.checked_rem(*rhs)
Expand All @@ -814,35 +814,35 @@ impl ArithmeticResult {
}
(ArithmeticValue::Float(lhs), ArithmeticValue::Float(rhs)) => {
if *rhs == 0.0 {
return Err(miette::miette!("Modulo by zero: {} % {}", lhs, rhs));
miette::bail!("Modulo by zero: {} % {}", lhs, rhs);
}
let remainder = lhs % rhs;
if remainder.is_finite() {
ArithmeticValue::Float(remainder)
} else {
return Err(miette::miette!("Float overflow: {} % {}", lhs, rhs));
miette::bail!("Float overflow: {} % {}", lhs, rhs);
}
}
(ArithmeticValue::Integer(lhs), ArithmeticValue::Float(rhs)) => {
if *rhs == 0.0 {
return Err(miette::miette!("Modulo by zero: {} % {}", lhs, rhs));
miette::bail!("Modulo by zero: {} % {}", lhs, rhs);
}
let remainder = *lhs as f64 % rhs;
if remainder.is_finite() {
ArithmeticValue::Float(remainder)
} else {
return Err(miette::miette!("Float overflow: {} % {}", lhs, rhs));
miette::bail!("Float overflow: {} % {}", lhs, rhs);
}
}
(ArithmeticValue::Float(lhs), ArithmeticValue::Integer(rhs)) => {
if *rhs == 0 {
return Err(miette::miette!("Modulo by zero: {} % {}", lhs, rhs));
miette::bail!("Modulo by zero: {} % {}", lhs, rhs);
}
let remainder = lhs % *rhs as f64;
if remainder.is_finite() {
ArithmeticValue::Float(remainder)
} else {
return Err(miette::miette!("Float overflow: {} % {}", lhs, rhs));
miette::bail!("Float overflow: {} % {}", lhs, rhs);
}
}
};
Expand All @@ -867,7 +867,7 @@ impl ArithmeticResult {
if result.is_finite() {
ArithmeticValue::Float(result)
} else {
return Err(miette::miette!("Float overflow: {} ** {}", lhs, rhs));
miette::bail!("Float overflow: {} ** {}", lhs, rhs);
}
} else {
lhs
Expand All @@ -883,23 +883,23 @@ impl ArithmeticResult {
if result.is_finite() {
ArithmeticValue::Float(result)
} else {
return Err(miette::miette!("Float overflow: {} ** {}", lhs, rhs));
miette::bail!("Float overflow: {} ** {}", lhs, rhs);
}
}
(ArithmeticValue::Integer(lhs), ArithmeticValue::Float(rhs)) => {
let result = (*lhs as f64).powf(*rhs);
if result.is_finite() {
ArithmeticValue::Float(result)
} else {
return Err(miette::miette!("Float overflow: {} ** {}", lhs, rhs));
miette::bail!("Float overflow: {} ** {}", lhs, rhs);
}
}
(ArithmeticValue::Float(lhs), ArithmeticValue::Integer(rhs)) => {
let result = lhs.powf(*rhs as f64);
if result.is_finite() {
ArithmeticValue::Float(result)
} else {
return Err(miette::miette!("Float overflow: {} ** {}", lhs, rhs));
miette::bail!("Float overflow: {} ** {}", lhs, rhs);
}
}
};
Expand All @@ -924,7 +924,7 @@ impl ArithmeticResult {
if result.is_finite() {
ArithmeticValue::Float(result)
} else {
return Err(miette::miette!("Float overflow: -{}", val));
miette::bail!("Float overflow: -{}", val);
}
}
};
Expand Down

0 comments on commit 2325289

Please sign in to comment.