directly passing starlark error

This commit is contained in:
kevin zhao
2025-11-13 14:14:58 -05:00
parent 820e26f9d2
commit ae17058704
2 changed files with 5 additions and 5 deletions

View File

@@ -1,8 +1,9 @@
use starlark::Error as StarlarkError;
use thiserror::Error;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Error, PartialEq, Eq)]
#[derive(Debug, Error)]
pub enum Error {
#[error("invalid decision: {0}")]
InvalidDecision(String),
@@ -21,5 +22,5 @@ pub enum Error {
#[error("expected example to not match rule `{rule}`: {example}")]
ExampleDidMatch { rule: String, example: String },
#[error("starlark error: {0}")]
Starlark(String),
Starlark(StarlarkError),
}

View File

@@ -41,7 +41,7 @@ impl PolicyParser {
policy_file_contents.to_string(),
&dialect,
)
.map_err(|e| Error::Starlark(e.to_string()))?;
.map_err(Error::Starlark)?;
let globals = GlobalsBuilder::standard().with(policy_builtins).build();
let module = Module::new();
@@ -49,8 +49,7 @@ impl PolicyParser {
{
let mut eval = Evaluator::new(&module);
eval.extra = Some(&builder);
eval.eval_module(ast, &globals)
.map_err(|e| Error::Starlark(e.to_string()))?;
eval.eval_module(ast, &globals).map_err(Error::Starlark)?;
}
Ok(builder.build())
}