mirror of
https://github.com/openai/codex.git
synced 2026-09-14 11:57:03 +00:00
directly passing starlark error
This commit is contained in:
@@ -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),
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user