difftreelog
refactor drop runtime_error! usage
in: master
4 files changed
crates/jrsonnet-stdlib/src/arrays.rsdiffbeforeafterboth3use jrsonnet_evaluator::{3use jrsonnet_evaluator::{4 Either, IStr, ObjValue, ObjValueBuilder, Result, ResultExt, Thunk, Val, bail, error,4 Either, IStr, ObjValue, ObjValueBuilder, Result, ResultExt, Thunk, Val, bail, error,5 function::{NativeFn, builtin},5 function::{NativeFn, builtin},6 runtime_error,7 typed::{BoundedUsize, Either2, FromUntyped},6 typed::{BoundedUsize, Either2, FromUntyped},8 val::{ArrValue, IndexableVal, equals},7 val::{ArrValue, IndexableVal, equals},9};8};40 Ok(match what {39 Ok(match what {41 Either2::A(s) => Val::string(s.repeat(count as usize)),40 Either2::A(s) => Val::string(s.repeat(count as usize)),42 Either2::B(arr) => Val::Arr(41 Either2::B(arr) => Val::Arr(43 ArrValue::repeated(arr, count)42 ArrValue::repeated(arr, count).ok_or_else(|| error!("repeated length overflow"))?,44 .ok_or_else(|| runtime_error!("repeated length overflow"))?,45 ),43 ),46 })44 })47}45}crates/jrsonnet-stdlib/src/encoding.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/encoding.rs
+++ b/crates/jrsonnet-stdlib/src/encoding.rs
@@ -1,8 +1,7 @@
use base64::{Engine, engine::general_purpose::STANDARD};
use jrsonnet_evaluator::{
- IBytes, IStr, Result, bail,
+ IBytes, IStr, Result, bail, error,
function::builtin,
- runtime_error,
typed::{Either, Either2},
};
@@ -35,7 +34,7 @@
pub fn builtin_base64_decode_bytes(str: IStr) -> Result<IBytes> {
Ok(STANDARD
.decode(str.as_bytes())
- .map_err(|e| runtime_error!("invalid base64: {e}"))?
+ .map_err(|e| error!("invalid base64: {e}"))?
.as_slice()
.into())
}
@@ -44,10 +43,10 @@
pub fn builtin_base64_decode(str: IStr, #[default(false)] lossy: bool) -> Result<String> {
let bytes = STANDARD
.decode(str.as_bytes())
- .map_err(|e| runtime_error!("invalid base64: {e}"))?;
+ .map_err(|e| error!("invalid base64: {e}"))?;
if lossy {
Ok(String::from_utf8_lossy(&bytes).to_string())
} else {
- String::from_utf8(bytes).map_err(|e| runtime_error!("bad utf8: {e}"))
+ String::from_utf8(bytes).map_err(|e| error!("bad utf8: {e}"))
}
}
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}"))?,
)),
})
}