difftreelog
refactor unify throw & throw_runtime
in: master
13 files changed
crates/jrsonnet-evaluator/src/error.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/error.rs
+++ b/crates/jrsonnet-evaluator/src/error.rs
@@ -266,14 +266,13 @@
#[macro_export]
macro_rules! throw {
- ($e: expr) => {
- return Err($e.into())
+ ($w:ident$(::$i:ident)*$(($($tt:tt)*))?) => {
+ return Err($w$(::$i)*$(($($tt)*))?.into())
};
-}
-
-#[macro_export]
-macro_rules! throw_runtime {
- ($($tt:tt)*) => {
- return Err($crate::error::Error::RuntimeError(format!($($tt)*).into()).into())
+ ($l:literal) => {
+ return Err($crate::error::Error::RuntimeError($l.into()).into())
+ };
+ ($l:literal, $($tt:tt)*) => {
+ return Err($crate::error::Error::RuntimeError(format!($l, $($tt)*).into()).into())
};
}
crates/jrsonnet-evaluator/src/evaluate/destructure.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/evaluate/destructure.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/destructure.rs
@@ -32,7 +32,7 @@
Destruct::Array { start, rest, end } => {
use jrsonnet_parser::DestructRest;
- use crate::{throw_runtime, val::ArrValue};
+ use crate::{throw, val::ArrValue};
#[derive(Trace)]
struct DataThunk {
@@ -47,14 +47,14 @@
let v = self.parent.evaluate(s)?;
let arr = match v {
Val::Arr(a) => a,
- _ => throw_runtime!("expected array"),
+ _ => throw!("expected array"),
};
if !self.has_rest {
if arr.len() != self.min_len {
- throw_runtime!("expected {} elements, got {}", self.min_len, arr.len())
+ throw!("expected {} elements, got {}", self.min_len, arr.len())
}
} else if arr.len() < self.min_len {
- throw_runtime!(
+ throw!(
"expected at least {} elements, but array was only {}",
self.min_len,
arr.len()
@@ -163,7 +163,7 @@
}
#[cfg(feature = "exp-destruct")]
Destruct::Object { fields, rest } => {
- use crate::{obj::ObjValue, throw_runtime};
+ use crate::{obj::ObjValue, throw};
#[derive(Trace)]
struct DataThunk {
@@ -178,17 +178,17 @@
let v = self.parent.evaluate(s)?;
let obj = match v {
Val::Obj(o) => o,
- _ => throw_runtime!("expected object"),
+ _ => throw!("expected object"),
};
for field in &self.field_names {
if !obj.has_field_ex(field.clone(), true) {
- throw_runtime!("missing field: {}", field);
+ throw!("missing field: {}", field);
}
}
if !self.has_rest {
let len = obj.len();
if len != self.field_names.len() {
- throw_runtime!("too many fields, and rest not found");
+ throw!("too many fields, and rest not found");
}
}
Ok(obj)
crates/jrsonnet-evaluator/src/evaluate/operator.rsdiffbeforeafterboth1use std::cmp::Ordering;23use jrsonnet_parser::{BinaryOpType, LocExpr, UnaryOpType};45use crate::{6 error::Error::*, evaluate, stdlib::std_format, throw, typed::Typed, val::equals, Context,7 Result, State, Val,8};910pub fn evaluate_unary_op(op: UnaryOpType, b: &Val) -> Result<Val> {11 use UnaryOpType::*;12 use Val::*;13 Ok(match (op, b) {14 (Not, Bool(v)) => Bool(!v),15 (Minus, Num(n)) => Num(-*n),16 (BitNot, Num(n)) => Num(f64::from(!(*n as i32))),17 (op, o) => throw!(UnaryOperatorDoesNotOperateOnType(op, o.value_type())),18 })19}2021pub fn evaluate_add_op(s: State, a: &Val, b: &Val) -> Result<Val> {22 use Val::*;23 Ok(match (a, b) {24 (Str(a), Str(b)) if a.is_empty() => Val::Str(b.clone()),25 (Str(a), Str(b)) if b.is_empty() => Val::Str(a.clone()),26 (Str(v1), Str(v2)) => Str(((**v1).to_owned() + v2).into()),2728 // Can't use generic json serialization way, because it depends on number to string concatenation (std.jsonnet:890)29 (Num(a), Str(b)) => Str(format!("{a}{b}").into()),30 (Str(a), Num(b)) => Str(format!("{a}{b}").into()),3132 (Str(a), o) | (o, Str(a)) if a.is_empty() => Val::Str(o.clone().to_string(s)?),33 (Str(a), o) => Str(format!("{a}{}", o.clone().to_string(s)?).into()),34 (o, Str(a)) => Str(format!("{}{a}", o.clone().to_string(s)?).into()),3536 (Obj(v1), Obj(v2)) => Obj(v2.extend_from(v1.clone())),37 (Arr(a), Arr(b)) => {38 let mut out = Vec::with_capacity(a.len() + b.len());39 out.extend(a.iter_lazy());40 out.extend(b.iter_lazy());41 Arr(out.into())42 }43 (Num(v1), Num(v2)) => Val::new_checked_num(v1 + v2)?,44 _ => throw!(BinaryOperatorDoesNotOperateOnValues(45 BinaryOpType::Add,46 a.value_type(),47 b.value_type(),48 )),49 })50}5152pub fn evaluate_mod_op(s: State, a: &Val, b: &Val) -> Result<Val> {53 use Val::*;54 match (a, b) {55 (Num(a), Num(b)) => {56 if *b == 0.0 {57 throw!(DivisionByZero)58 }59 Ok(Num(a % b))60 }61 (Str(str), vals) => {62 String::into_untyped(std_format(s.clone(), str.clone(), vals.clone())?, s)63 }64 (a, b) => throw!(BinaryOperatorDoesNotOperateOnValues(65 BinaryOpType::Mod,66 a.value_type(),67 b.value_type()68 )),69 }70}7172pub fn evaluate_binary_op_special(73 s: State,74 ctx: Context,75 a: &LocExpr,76 op: BinaryOpType,77 b: &LocExpr,78) -> Result<Val> {79 use BinaryOpType::*;80 use Val::*;81 Ok(match (evaluate(s.clone(), ctx.clone(), a)?, op, b) {82 (Bool(true), Or, _o) => Val::Bool(true),83 (Bool(false), And, _o) => Val::Bool(false),84 (a, op, eb) => evaluate_binary_op_normal(s.clone(), &a, op, &evaluate(s, ctx, eb)?)?,85 })86}8788pub fn evaluate_compare_op(s: State, a: &Val, op: BinaryOpType, b: &Val) -> Result<Ordering> {89 use Val::*;90 Ok(match (a, b) {91 (Str(a), Str(b)) => a.cmp(b),92 (Num(a), Num(b)) => a.partial_cmp(b).expect("jsonnet numbers are non NaN"),93 (Arr(a), Arr(b)) => {94 let ai = a.iter(s.clone());95 let bi = b.iter(s.clone());9697 for (a, b) in ai.zip(bi) {98 let ord = evaluate_compare_op(s.clone(), &a?, op, &b?)?;99 if !ord.is_eq() {100 return Ok(ord);101 }102 }103104 a.len().cmp(&b.len())105 }106 (_, _) => throw!(BinaryOperatorDoesNotOperateOnValues(107 op,108 a.value_type(),109 b.value_type()110 )),111 })112}113114pub fn evaluate_binary_op_normal(s: State, a: &Val, op: BinaryOpType, b: &Val) -> Result<Val> {115 use BinaryOpType::*;116 use Val::*;117 Ok(match (a, op, b) {118 (a, Add, b) => evaluate_add_op(s, a, b)?,119120 (a, Eq, b) => Bool(equals(s, a, b)?),121 (a, Neq, b) => Bool(!equals(s, a, b)?),122123 (a, Lt, b) => Bool(evaluate_compare_op(s, a, Lt, b)?.is_lt()),124 (a, Gt, b) => Bool(evaluate_compare_op(s, a, Gt, b)?.is_gt()),125 (a, Lte, b) => Bool(evaluate_compare_op(s, a, Lte, b)?.is_le()),126 (a, Gte, b) => Bool(evaluate_compare_op(s, a, Gte, b)?.is_ge()),127128 (Str(a), In, Obj(obj)) => Bool(obj.has_field_ex(a.clone(), true)),129 (a, Mod, b) => evaluate_mod_op(s, a, b)?,130131 (Str(v1), Mul, Num(v2)) => Str(v1.repeat(*v2 as usize).into()),132133 // Bool X Bool134 (Bool(a), And, Bool(b)) => Bool(*a && *b),135 (Bool(a), Or, Bool(b)) => Bool(*a || *b),136137 // Num X Num138 (Num(v1), Mul, Num(v2)) => Val::new_checked_num(v1 * v2)?,139 (Num(v1), Div, Num(v2)) => {140 if *v2 == 0.0 {141 throw!(DivisionByZero)142 }143 Val::new_checked_num(v1 / v2)?144 }145146 (Num(v1), Sub, Num(v2)) => Val::new_checked_num(v1 - v2)?,147148 (Num(v1), BitAnd, Num(v2)) => Num(f64::from((*v1 as i32) & (*v2 as i32))),149 (Num(v1), BitOr, Num(v2)) => Num(f64::from((*v1 as i32) | (*v2 as i32))),150 (Num(v1), BitXor, Num(v2)) => Num(f64::from((*v1 as i32) ^ (*v2 as i32))),151 (Num(v1), Lhs, Num(v2)) => {152 if *v2 < 0.0 {153 throw!(RuntimeError("shift by negative exponent".into()))154 }155 Num(f64::from((*v1 as i32) << (*v2 as i32)))156 }157 (Num(v1), Rhs, Num(v2)) => {158 if *v2 < 0.0 {159 throw!(RuntimeError("shift by negative exponent".into()))160 }161 Num(f64::from((*v1 as i32) >> (*v2 as i32)))162 }163164 _ => throw!(BinaryOperatorDoesNotOperateOnValues(165 op,166 a.value_type(),167 b.value_type(),168 )),169 })170}1use std::cmp::Ordering;23use jrsonnet_parser::{BinaryOpType, LocExpr, UnaryOpType};45use crate::{6 error::Error::*, evaluate, stdlib::std_format, throw, typed::Typed, val::equals, Context,7 Result, State, Val,8};910pub fn evaluate_unary_op(op: UnaryOpType, b: &Val) -> Result<Val> {11 use UnaryOpType::*;12 use Val::*;13 Ok(match (op, b) {14 (Not, Bool(v)) => Bool(!v),15 (Minus, Num(n)) => Num(-*n),16 (BitNot, Num(n)) => Num(f64::from(!(*n as i32))),17 (op, o) => throw!(UnaryOperatorDoesNotOperateOnType(op, o.value_type())),18 })19}2021pub fn evaluate_add_op(s: State, a: &Val, b: &Val) -> Result<Val> {22 use Val::*;23 Ok(match (a, b) {24 (Str(a), Str(b)) if a.is_empty() => Val::Str(b.clone()),25 (Str(a), Str(b)) if b.is_empty() => Val::Str(a.clone()),26 (Str(v1), Str(v2)) => Str(((**v1).to_owned() + v2).into()),2728 // Can't use generic json serialization way, because it depends on number to string concatenation (std.jsonnet:890)29 (Num(a), Str(b)) => Str(format!("{a}{b}").into()),30 (Str(a), Num(b)) => Str(format!("{a}{b}").into()),3132 (Str(a), o) | (o, Str(a)) if a.is_empty() => Val::Str(o.clone().to_string(s)?),33 (Str(a), o) => Str(format!("{a}{}", o.clone().to_string(s)?).into()),34 (o, Str(a)) => Str(format!("{}{a}", o.clone().to_string(s)?).into()),3536 (Obj(v1), Obj(v2)) => Obj(v2.extend_from(v1.clone())),37 (Arr(a), Arr(b)) => {38 let mut out = Vec::with_capacity(a.len() + b.len());39 out.extend(a.iter_lazy());40 out.extend(b.iter_lazy());41 Arr(out.into())42 }43 (Num(v1), Num(v2)) => Val::new_checked_num(v1 + v2)?,44 _ => throw!(BinaryOperatorDoesNotOperateOnValues(45 BinaryOpType::Add,46 a.value_type(),47 b.value_type(),48 )),49 })50}5152pub fn evaluate_mod_op(s: State, a: &Val, b: &Val) -> Result<Val> {53 use Val::*;54 match (a, b) {55 (Num(a), Num(b)) => {56 if *b == 0.0 {57 throw!(DivisionByZero)58 }59 Ok(Num(a % b))60 }61 (Str(str), vals) => {62 String::into_untyped(std_format(s.clone(), str.clone(), vals.clone())?, s)63 }64 (a, b) => throw!(BinaryOperatorDoesNotOperateOnValues(65 BinaryOpType::Mod,66 a.value_type(),67 b.value_type()68 )),69 }70}7172pub fn evaluate_binary_op_special(73 s: State,74 ctx: Context,75 a: &LocExpr,76 op: BinaryOpType,77 b: &LocExpr,78) -> Result<Val> {79 use BinaryOpType::*;80 use Val::*;81 Ok(match (evaluate(s.clone(), ctx.clone(), a)?, op, b) {82 (Bool(true), Or, _o) => Val::Bool(true),83 (Bool(false), And, _o) => Val::Bool(false),84 (a, op, eb) => evaluate_binary_op_normal(s.clone(), &a, op, &evaluate(s, ctx, eb)?)?,85 })86}8788pub fn evaluate_compare_op(s: State, a: &Val, op: BinaryOpType, b: &Val) -> Result<Ordering> {89 use Val::*;90 Ok(match (a, b) {91 (Str(a), Str(b)) => a.cmp(b),92 (Num(a), Num(b)) => a.partial_cmp(b).expect("jsonnet numbers are non NaN"),93 (Arr(a), Arr(b)) => {94 let ai = a.iter(s.clone());95 let bi = b.iter(s.clone());9697 for (a, b) in ai.zip(bi) {98 let ord = evaluate_compare_op(s.clone(), &a?, op, &b?)?;99 if !ord.is_eq() {100 return Ok(ord);101 }102 }103104 a.len().cmp(&b.len())105 }106 (_, _) => throw!(BinaryOperatorDoesNotOperateOnValues(107 op,108 a.value_type(),109 b.value_type()110 )),111 })112}113114pub fn evaluate_binary_op_normal(s: State, a: &Val, op: BinaryOpType, b: &Val) -> Result<Val> {115 use BinaryOpType::*;116 use Val::*;117 Ok(match (a, op, b) {118 (a, Add, b) => evaluate_add_op(s, a, b)?,119120 (a, Eq, b) => Bool(equals(s, a, b)?),121 (a, Neq, b) => Bool(!equals(s, a, b)?),122123 (a, Lt, b) => Bool(evaluate_compare_op(s, a, Lt, b)?.is_lt()),124 (a, Gt, b) => Bool(evaluate_compare_op(s, a, Gt, b)?.is_gt()),125 (a, Lte, b) => Bool(evaluate_compare_op(s, a, Lte, b)?.is_le()),126 (a, Gte, b) => Bool(evaluate_compare_op(s, a, Gte, b)?.is_ge()),127128 (Str(a), In, Obj(obj)) => Bool(obj.has_field_ex(a.clone(), true)),129 (a, Mod, b) => evaluate_mod_op(s, a, b)?,130131 (Str(v1), Mul, Num(v2)) => Str(v1.repeat(*v2 as usize).into()),132133 // Bool X Bool134 (Bool(a), And, Bool(b)) => Bool(*a && *b),135 (Bool(a), Or, Bool(b)) => Bool(*a || *b),136137 // Num X Num138 (Num(v1), Mul, Num(v2)) => Val::new_checked_num(v1 * v2)?,139 (Num(v1), Div, Num(v2)) => {140 if *v2 == 0.0 {141 throw!(DivisionByZero)142 }143 Val::new_checked_num(v1 / v2)?144 }145146 (Num(v1), Sub, Num(v2)) => Val::new_checked_num(v1 - v2)?,147148 (Num(v1), BitAnd, Num(v2)) => Num(f64::from((*v1 as i32) & (*v2 as i32))),149 (Num(v1), BitOr, Num(v2)) => Num(f64::from((*v1 as i32) | (*v2 as i32))),150 (Num(v1), BitXor, Num(v2)) => Num(f64::from((*v1 as i32) ^ (*v2 as i32))),151 (Num(v1), Lhs, Num(v2)) => {152 if *v2 < 0.0 {153 throw!("shift by negative exponent")154 }155 Num(f64::from((*v1 as i32) << (*v2 as i32)))156 }157 (Num(v1), Rhs, Num(v2)) => {158 if *v2 < 0.0 {159 throw!("shift by negative exponent")160 }161 Num(f64::from((*v1 as i32) >> (*v2 as i32)))162 }163164 _ => throw!(BinaryOperatorDoesNotOperateOnValues(165 op,166 a.value_type(),167 b.value_type(),168 )),169 })170}crates/jrsonnet-evaluator/src/integrations/serde.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/integrations/serde.rs
+++ b/crates/jrsonnet-evaluator/src/integrations/serde.rs
@@ -72,7 +72,7 @@
}
Self::Object(out)
}
- Val::Func(_) => throw!(RuntimeError("tried to manifest function".into())),
+ Val::Func(_) => throw!("tried to manifest function"),
})
}
}
crates/jrsonnet-evaluator/src/stdlib/format.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/stdlib/format.rs
+++ b/crates/jrsonnet-evaluator/src/stdlib/format.rs
@@ -591,9 +591,7 @@
),
Val::Str(s) => {
if s.chars().count() != 1 {
- throw!(RuntimeError(
- format!("%c expected 1 char string, got {}", s.chars().count()).into(),
- ));
+ throw!("%c expected 1 char string, got {}", s.chars().count(),);
}
tmp_out.push_str(&s);
}
crates/jrsonnet-evaluator/src/stdlib/manifest.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/stdlib/manifest.rs
+++ b/crates/jrsonnet-evaluator/src/stdlib/manifest.rs
@@ -341,7 +341,7 @@
}
}
}
- Val::Func(_) => throw!(RuntimeError("tried to manifest function".into())),
+ Val::Func(_) => throw!("tried to manifest function"),
}
Ok(())
}
crates/jrsonnet-evaluator/src/typed/conversions.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/typed/conversions.rs
+++ b/crates/jrsonnet-evaluator/src/typed/conversions.rs
@@ -6,7 +6,7 @@
use jrsonnet_types::{ComplexValType, ValType};
use crate::{
- error::{Error::*, Result},
+ error::Result,
function::{FuncDesc, FuncVal},
throw,
typed::CheckType,
@@ -41,13 +41,10 @@
Val::Num(n) => {
#[allow(clippy::float_cmp)]
if n.trunc() != n {
- throw!(RuntimeError(
- format!(
- "cannot convert number with fractional part to {}",
- stringify!($ty)
- )
- .into()
- ))
+ throw!(
+ "cannot convert number with fractional part to {}",
+ stringify!($ty)
+ )
}
Ok(n as Self)
}
@@ -99,13 +96,10 @@
Val::Num(n) => {
#[allow(clippy::float_cmp)]
if n.trunc() != n {
- throw!(RuntimeError(
- format!(
- "cannot convert number with fractional part to {}",
- stringify!($ty)
- )
- .into()
- ))
+ throw!(
+ "cannot convert number with fractional part to {}",
+ stringify!($ty)
+ )
}
Ok(Self(n as $ty))
}
@@ -167,7 +161,7 @@
fn into_untyped(value: Self, _: State) -> Result<Val> {
if value > u32::MAX as Self {
- throw!(RuntimeError("number is too large".into()))
+ throw!("number is too large")
}
Ok(Val::Num(value as f64))
}
@@ -178,9 +172,7 @@
Val::Num(n) => {
#[allow(clippy::float_cmp)]
if n.trunc() != n {
- throw!(RuntimeError(
- "cannot convert number with fractional part to usize".into()
- ))
+ throw!("cannot convert number with fractional part to usize")
}
Ok(n as Self)
}
@@ -440,7 +432,7 @@
<Self as Typed>::TYPE.check(s, &value)?;
match value {
Val::Func(FuncVal::Normal(desc)) => Ok(desc),
- Val::Func(_) => throw!(RuntimeError("expected normal function, not builtin".into())),
+ Val::Func(_) => throw!("expected normal function, not builtin"),
_ => unreachable!(),
}
}
crates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/val.rs
+++ b/crates/jrsonnet-evaluator/src/val.rs
@@ -629,7 +629,7 @@
if num.is_finite() {
Ok(Self::Num(num))
} else {
- throw!(RuntimeError("overflow".into()))
+ throw!("overflow")
}
}
@@ -843,14 +843,14 @@
(Val::Null, Val::Null) => true,
(Val::Str(a), Val::Str(b)) => a == b,
(Val::Num(a), Val::Num(b)) => (a - b).abs() <= f64::EPSILON,
- (Val::Arr(_), Val::Arr(_)) => throw!(RuntimeError(
- "primitiveEquals operates on primitive types, got array".into(),
- )),
- (Val::Obj(_), Val::Obj(_)) => throw!(RuntimeError(
- "primitiveEquals operates on primitive types, got object".into(),
- )),
+ (Val::Arr(_), Val::Arr(_)) => {
+ throw!("primitiveEquals operates on primitive types, got array")
+ }
+ (Val::Obj(_), Val::Obj(_)) => {
+ throw!("primitiveEquals operates on primitive types, got object")
+ }
(a, b) if is_function_like(a) && is_function_like(b) => {
- throw!(RuntimeError("cannot test equality of functions".into()))
+ throw!("cannot test equality of functions")
}
(_, _) => false,
})
crates/jrsonnet-stdlib/src/arrays.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/arrays.rs
+++ b/crates/jrsonnet-stdlib/src/arrays.rs
@@ -1,7 +1,7 @@
use jrsonnet_evaluator::{
error::Result,
function::{builtin, FuncVal},
- throw_runtime,
+ throw,
typed::{Any, BoundedUsize, Typed, VecVal},
val::{equals, ArrValue, IndexableVal},
IStr, State, Val,
@@ -43,7 +43,7 @@
match func.evaluate_simple(s.clone(), &(c.to_string(),))? {
Val::Str(o) => out.push_str(&o),
Val::Null => continue,
- _ => throw_runtime!("in std.join all items should be strings"),
+ _ => throw!("in std.join all items should be strings"),
};
}
Ok(IndexableVal::Str(out.into()))
@@ -59,7 +59,7 @@
}
}
Val::Null => continue,
- _ => throw_runtime!("in std.join all items should be arrays"),
+ _ => throw!("in std.join all items should be arrays"),
};
}
Ok(IndexableVal::Arr(out.into()))
@@ -128,7 +128,7 @@
} else if matches!(item, Val::Null) {
continue;
} else {
- throw_runtime!("in std.join all items should be arrays");
+ throw!("in std.join all items should be arrays");
}
}
@@ -149,7 +149,7 @@
} else if matches!(item, Val::Null) {
continue;
} else {
- throw_runtime!("in std.join all items should be strings");
+ throw!("in std.join all items should be strings");
}
}
crates/jrsonnet-stdlib/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/lib.rs
+++ b/crates/jrsonnet-stdlib/src/lib.rs
@@ -8,7 +8,7 @@
error::{Error::*, Result},
function::{builtin::Builtin, ArgLike, CallLocation, FuncVal, TlaArg},
gc::{GcHashMap, TraceBox},
- tb, throw_runtime,
+ tb, throw,
trace::PathResolver,
typed::{Any, Either, Either2, Either4, VecVal, M1},
val::{equals, ArrValue},
@@ -500,7 +500,7 @@
true
}
}
- _ => throw_runtime!("both arguments should be of the same type"),
+ _ => throw!("both arguments should be of the same type"),
})
}
@@ -534,7 +534,7 @@
true
}
}
- _ => throw_runtime!("both arguments should be of the same type"),
+ _ => throw!("both arguments should be of the same type"),
})
}
crates/jrsonnet-stdlib/src/sort.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/sort.rs
+++ b/crates/jrsonnet-stdlib/src/sort.rs
@@ -1,7 +1,7 @@
use jrsonnet_evaluator::{
error::Result,
function::{builtin, FuncVal},
- throw_runtime,
+ throw,
typed::Any,
val::ArrValue,
State, Val,
@@ -41,9 +41,9 @@
(Val::Num(_), SortKeyType::Unknown) => sort_type = SortKeyType::Number,
(Val::Str(_), SortKeyType::String) | (Val::Num(_), SortKeyType::Number) => {}
(Val::Str(_) | Val::Num(_), _) => {
- throw_runtime!("sort elements should have the same types")
+ throw!("sort elements should have the same types")
}
- _ => throw_runtime!("sort key should either be a string or a number"),
+ _ => throw!("sort key should either be a string or a number"),
}
}
Ok(sort_type)
tests/tests/common.rsdiffbeforeafterboth--- a/tests/tests/common.rs
+++ b/tests/tests/common.rs
@@ -1,7 +1,7 @@
use jrsonnet_evaluator::{
error::Result,
function::{builtin, FuncVal},
- throw_runtime, ObjValueBuilder, State, Thunk, Val,
+ throw, ObjValueBuilder, State, Thunk, Val,
};
use jrsonnet_stdlib::StateExt;
@@ -11,7 +11,7 @@
let a = &$a;
let b = &$b;
if a != b {
- ::jrsonnet_evaluator::throw_runtime!("assertion failed: a != b\na={:#?}\nb={:#?}", a, b)
+ ::jrsonnet_evaluator::throw!("assertion failed: a != b\na={:#?}\nb={:#?}", a, b)
}
}};
}
@@ -20,7 +20,7 @@
macro_rules! ensure {
($v:expr $(,)?) => {
if !$v {
- ::jrsonnet_evaluator::throw_runtime!("assertion failed: {}", stringify!($v))
+ ::jrsonnet_evaluator::throw!("assertion failed: {}", stringify!($v))
}
};
}
@@ -29,7 +29,7 @@
macro_rules! ensure_val_eq {
($s:expr, $a:expr, $b:expr) => {{
if !::jrsonnet_evaluator::val::equals($s.clone(), &$a.clone(), &$b.clone())? {
- ::jrsonnet_evaluator::throw_runtime!(
+ ::jrsonnet_evaluator::throw!(
"assertion failed: a != b\na={:#?}\nb={:#?}",
$a.to_json(
$s.clone(),
@@ -52,7 +52,7 @@
fn assert_throw(s: State, lazy: Thunk<Val>, message: String) -> Result<bool> {
match lazy.evaluate(s) {
Ok(_) => {
- throw_runtime!("expected argument to throw on evaluation, but it returned instead")
+ throw!("expected argument to throw on evaluation, but it returned instead")
}
Err(e) => {
let error = format!("{}", e.error());
tests/tests/sanity.rsdiffbeforeafterboth--- a/tests/tests/sanity.rs
+++ b/tests/tests/sanity.rs
@@ -1,4 +1,4 @@
-use jrsonnet_evaluator::{error::Result, throw_runtime, State, Val};
+use jrsonnet_evaluator::{error::Result, throw, State, Val};
use jrsonnet_stdlib::StateExt;
mod common;
@@ -23,7 +23,7 @@
{
let e = match s.evaluate_snippet("snip".to_owned(), "assert 1 == 2: 'fail'; null") {
- Ok(_) => throw_runtime!("assertion should fail"),
+ Ok(_) => throw!("assertion should fail"),
Err(e) => e,
};
let e = s.stringify_err(&e);
@@ -31,7 +31,7 @@
}
{
let e = match s.evaluate_snippet("snip".to_owned(), "std.assertEqual(1, 2)") {
- Ok(_) => throw_runtime!("assertion should fail"),
+ Ok(_) => throw!("assertion should fail"),
Err(e) => e,
};
let e = s.stringify_err(&e);