difftreelog
refactor drop runtime_error! usage
in: master
4 files changed
crates/jrsonnet-stdlib/src/arrays.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/arrays.rs
+++ b/crates/jrsonnet-stdlib/src/arrays.rs
@@ -3,7 +3,6 @@
use jrsonnet_evaluator::{
Either, IStr, ObjValue, ObjValueBuilder, Result, ResultExt, Thunk, Val, bail, error,
function::{NativeFn, builtin},
- runtime_error,
typed::{BoundedUsize, Either2, FromUntyped},
val::{ArrValue, IndexableVal, equals},
};
@@ -40,8 +39,7 @@
Ok(match what {
Either2::A(s) => Val::string(s.repeat(count as usize)),
Either2::B(arr) => Val::Arr(
- ArrValue::repeated(arr, count)
- .ok_or_else(|| runtime_error!("repeated length overflow"))?,
+ ArrValue::repeated(arr, count).ok_or_else(|| error!("repeated length overflow"))?,
),
})
}
crates/jrsonnet-stdlib/src/encoding.rsdiffbeforeafterboth1use base64::{Engine, engine::general_purpose::STANDARD};2use jrsonnet_evaluator::{3 IBytes, IStr, Result, bail,4 function::builtin,5 runtime_error,6 typed::{Either, Either2},7};89#[builtin]10pub fn builtin_encode_utf8(str: IStr) -> IBytes {11 str.cast_bytes()12}1314#[builtin]15pub fn builtin_decode_utf8(arr: IBytes, #[default(true)] lossy: bool) -> Result<IStr> {16 match arr.clone().cast_str() {17 Some(s) => Ok(s),18 None if lossy => Ok(String::from_utf8_lossy(arr.as_slice()).into()),19 None => {20 bail!("bad utf8")21 }22 }23}2425#[builtin]26pub fn builtin_base64(input: Either![IStr, IBytes]) -> String {27 use Either2::*;28 match input {29 A(l) => STANDARD.encode(l.as_bytes()),30 B(a) => STANDARD.encode(a.as_slice()),31 }32}3334#[builtin]35pub fn builtin_base64_decode_bytes(str: IStr) -> Result<IBytes> {36 Ok(STANDARD37 .decode(str.as_bytes())38 .map_err(|e| runtime_error!("invalid base64: {e}"))?39 .as_slice()40 .into())41}4243#[builtin]44pub fn builtin_base64_decode(str: IStr, #[default(false)] lossy: bool) -> Result<String> {45 let bytes = STANDARD46 .decode(str.as_bytes())47 .map_err(|e| runtime_error!("invalid base64: {e}"))?;48 if lossy {49 Ok(String::from_utf8_lossy(&bytes).to_string())50 } else {51 String::from_utf8(bytes).map_err(|e| runtime_error!("bad utf8: {e}"))52 }53}crates/jrsonnet-stdlib/src/parse.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/parse.rs
+++ b/crates/jrsonnet-stdlib/src/parse.rs
@@ -1,10 +1,9 @@
-use jrsonnet_evaluator::{IStr, Result, Val, function::builtin, runtime_error};
+use jrsonnet_evaluator::{IStr, Result, Val, error, function::builtin};
use serde_saphyr::options;
#[builtin]
pub fn builtin_parse_json(str: IStr) -> Result<Val> {
- let value: Val =
- serde_json::from_str(&str).map_err(|e| runtime_error!("failed to parse json: {e}"))?;
+ let value: Val = serde_json::from_str(&str).map_err(|e| error!("failed to parse json: {e}"))?;
Ok(value)
}
@@ -21,7 +20,7 @@
budget: None,
},
)
- .map_err(|e| runtime_error!("failed to parse yaml: {e}"))?;
+ .map_err(|e| error!("failed to parse yaml: {e}"))?;
// saphyr and other yaml implementations disagree on how to handle an empty document in multi-document stream.
// Saphyr only considers document started after anything is emitted after the document delimiter
crates/jrsonnet-stdlib/src/strings.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/strings.rs
+++ b/crates/jrsonnet-stdlib/src/strings.rs
@@ -206,17 +206,15 @@
#[builtin]
pub fn builtin_bigint(v: Either![f64, IStr]) -> Result<Val> {
use Either2::*;
- use jrsonnet_evaluator::runtime_error;
+ use jrsonnet_evaluator::error;
Ok(match v {
- A(a) => {
- Val::BigInt(Box::new(a.to_string().parse().map_err(|e| {
- runtime_error!("number is not convertible to bigint: {e}")
- })?))
- }
+ A(a) => Val::BigInt(Box::new(
+ a.to_string()
+ .parse()
+ .map_err(|e| error!("number is not convertible to bigint: {e}"))?,
+ )),
B(b) => Val::BigInt(Box::new(
- b.as_str()
- .parse()
- .map_err(|e| runtime_error!("bad bigint: {e}"))?,
+ b.as_str().parse().map_err(|e| error!("bad bigint: {e}"))?,
)),
})
}