mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
resolve anyhow compile errors (#355)
This commit is contained in:
@@ -32,8 +32,8 @@ if [ -f Cargo.toml ]; then
|
|||||||
|
|
||||||
# Ensure that all tests pass with extensions
|
# Ensure that all tests pass with extensions
|
||||||
cargo test -r --features rego-extensions
|
cargo test -r --features rego-extensions
|
||||||
cargo test -r --test aci rego-extensions
|
cargo test -r --test aci --features rego-extensions
|
||||||
cargo test -r --test kata rego-extensions
|
cargo test -r --test kata --features rego-extensions
|
||||||
|
|
||||||
# Ensure that OPA conformance tests don't regress.
|
# Ensure that OPA conformance tests don't regress.
|
||||||
cargo test -r --features opa-testutil,serde_json/arbitrary_precision,rego-extensions --test opa -- $(tr '\n' ' ' < tests/opa.passing)
|
cargo test -r --features opa-testutil,serde_json/arbitrary_precision,rego-extensions --test opa -- $(tr '\n' ' ' < tests/opa.passing)
|
||||||
|
|||||||
@@ -337,11 +337,11 @@ fn yaml_is_valid(
|
|||||||
fn yaml_marshal(span: &Span, params: &[Ref<Expr>], args: &[Value], _strict: bool) -> Result<Value> {
|
fn yaml_marshal(span: &Span, params: &[Ref<Expr>], args: &[Value], _strict: bool) -> Result<Value> {
|
||||||
let name = "yaml.marshal";
|
let name = "yaml.marshal";
|
||||||
ensure_args_count(span, name, params, args, 1)?;
|
ensure_args_count(span, name, params, args, 1)?;
|
||||||
Ok(Value::String(
|
|
||||||
serde_yaml::to_string(&args[0])
|
let serialized = serde_yaml::to_string(&args[0])
|
||||||
.with_context(|| span.error("could not serialize to yaml"))?
|
.map_err(|err| span.error(&format!("could not serialize to yaml: {}", err)))?;
|
||||||
.into(),
|
|
||||||
))
|
Ok(Value::String(serialized.into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "yaml")]
|
#[cfg(feature = "yaml")]
|
||||||
|
|||||||
@@ -439,7 +439,8 @@ fn json_match_schema(
|
|||||||
ensure_args_count(span, name, params, args, 2)?;
|
ensure_args_count(span, name, params, args, 2)?;
|
||||||
|
|
||||||
// The following is expected to succeed.
|
// The following is expected to succeed.
|
||||||
let document: serde_json::Value = serde_json::from_str(&args[0].to_json_str()?)?;
|
let document: serde_json::Value = serde_json::from_str(&args[0].to_json_str()?)
|
||||||
|
.map_err(|err| span.error(&format!("Failed to parse JSON: {}", err)))?;
|
||||||
|
|
||||||
Ok(Value::from_array(
|
Ok(Value::from_array(
|
||||||
match compile_json_schema(¶ms[1], &args[1]) {
|
match compile_json_schema(¶ms[1], &args[1]) {
|
||||||
|
|||||||
@@ -25,7 +25,11 @@ fn sleep(span: &Span, params: &[Ref<Expr>], args: &[Value], _strict: bool) -> Re
|
|||||||
let dur = time::compat::parse_duration(val.as_ref())
|
let dur = time::compat::parse_duration(val.as_ref())
|
||||||
.map_err(|e| params[0].span().error(&format!("{e}")))?;
|
.map_err(|e| params[0].span().error(&format!("{e}")))?;
|
||||||
|
|
||||||
thread::sleep(dur.to_std()?);
|
let std_dur = dur
|
||||||
|
.to_std()
|
||||||
|
.map_err(|err| anyhow::anyhow!("Failed to convert to std::time::Duration: {err}"))?;
|
||||||
|
|
||||||
|
thread::sleep(std_dur);
|
||||||
|
|
||||||
Ok(Value::Null)
|
Ok(Value::Null)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -158,7 +158,8 @@ fn parse_ns(span: &Span, params: &[Ref<Expr>], args: &[Value], strict: bool) ->
|
|||||||
let layout = ensure_string(name, ¶ms[0], &args[0])?;
|
let layout = ensure_string(name, ¶ms[0], &args[0])?;
|
||||||
let value = ensure_string(name, ¶ms[1], &args[1])?;
|
let value = ensure_string(name, ¶ms[1], &args[1])?;
|
||||||
|
|
||||||
let datetime = compat::parse(layout_with_predefined_formats(&layout), &value)?;
|
let datetime = compat::parse(layout_with_predefined_formats(&layout), &value)
|
||||||
|
.map_err(|err| anyhow::anyhow!("Failed to parse datetime: {}", err))?;
|
||||||
safe_timestamp_nanos(span, strict, datetime.timestamp_nanos_opt())
|
safe_timestamp_nanos(span, strict, datetime.timestamp_nanos_opt())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,7 +174,8 @@ fn parse_rfc3339_ns(
|
|||||||
|
|
||||||
let value = ensure_string(name, ¶ms[0], &args[0])?;
|
let value = ensure_string(name, ¶ms[0], &args[0])?;
|
||||||
|
|
||||||
let datetime = DateTime::parse_from_rfc3339(&value)?;
|
let datetime = DateTime::parse_from_rfc3339(&value)
|
||||||
|
.map_err(|err| anyhow::anyhow!("Failed to parse datetime: {}", err))?;
|
||||||
safe_timestamp_nanos(span, strict, datetime.timestamp_nanos_opt())
|
safe_timestamp_nanos(span, strict, datetime.timestamp_nanos_opt())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -266,7 +266,7 @@ struct GoTimeFormatItems<'a> {
|
|||||||
mode: GoTimeFormatItemsMode,
|
mode: GoTimeFormatItemsMode,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> GoTimeFormatItems<'a> {
|
impl GoTimeFormatItems<'_> {
|
||||||
fn parse(reminder: &str) -> GoTimeFormatItems {
|
fn parse(reminder: &str) -> GoTimeFormatItems {
|
||||||
GoTimeFormatItems {
|
GoTimeFormatItems {
|
||||||
reminder,
|
reminder,
|
||||||
|
|||||||
@@ -358,7 +358,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Implement clone for a boxed extension using [`Extension::clone_box`].
|
/// Implement clone for a boxed extension using [`Extension::clone_box`].
|
||||||
impl<'a> Clone for Box<dyn 'a + Extension> {
|
impl Clone for Box<dyn '_ + Extension> {
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
(**self).clone_box()
|
(**self).clone_box()
|
||||||
}
|
}
|
||||||
@@ -405,7 +405,6 @@ pub mod coverage {
|
|||||||
/// Lines that are not covered are red.
|
/// Lines that are not covered are red.
|
||||||
///
|
///
|
||||||
/// <img src="https://github.com/microsoft/regorus/blob/main/docs/coverage.png?raw=true">
|
/// <img src="https://github.com/microsoft/regorus/blob/main/docs/coverage.png?raw=true">
|
||||||
|
|
||||||
pub fn to_string_pretty(&self) -> anyhow::Result<String> {
|
pub fn to_string_pretty(&self) -> anyhow::Result<String> {
|
||||||
let mut s = String::default();
|
let mut s = String::default();
|
||||||
s.push_str("COVERAGE REPORT:\n");
|
s.push_str("COVERAGE REPORT:\n");
|
||||||
|
|||||||
@@ -405,7 +405,9 @@ impl Value {
|
|||||||
#[cfg(feature = "yaml")]
|
#[cfg(feature = "yaml")]
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||||
pub fn from_yaml_str(yaml: &str) -> Result<Value> {
|
pub fn from_yaml_str(yaml: &str) -> Result<Value> {
|
||||||
Ok(serde_yaml::from_str(yaml)?)
|
let value = serde_yaml::from_str(yaml)
|
||||||
|
.map_err(|err| anyhow::anyhow!("Failed to parse YAML: {}", err))?;
|
||||||
|
Ok(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Deserialize a value from a file containing YAML.
|
/// Deserialize a value from a file containing YAML.
|
||||||
|
|||||||
Reference in New Issue
Block a user