mirror of
https://github.com/gorules/zen.git
synced 2026-10-04 16:02:18 +00:00
fix: implement serializable errors; improve binding error transparency; (#62)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use crate::engine::PyZenEvaluateOptions;
|
||||
use crate::loader::PyDecisionLoader;
|
||||
use crate::value::PyValue;
|
||||
use anyhow::Context;
|
||||
use anyhow::{anyhow, Context};
|
||||
use pyo3::types::PyDict;
|
||||
use pyo3::{pyclass, pymethods, PyObject, PyResult, Python, ToPyObject};
|
||||
use pythonize::depythonize;
|
||||
@@ -36,7 +36,9 @@ impl PyZenDecision {
|
||||
trace: options.trace,
|
||||
},
|
||||
))
|
||||
.context("Failed to evaluate graph")?;
|
||||
.map_err(|e| {
|
||||
anyhow!(serde_json::to_string(e.as_ref()).unwrap_or_else(|_| e.to_string()))
|
||||
})?;
|
||||
|
||||
let value = serde_json::to_value(&result).context("Fail")?;
|
||||
Ok(PyValue(value).to_object(py))
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::decision::PyZenDecision;
|
||||
use crate::loader::PyDecisionLoader;
|
||||
use crate::value::PyValue;
|
||||
use anyhow::Context;
|
||||
use anyhow::{anyhow, Context};
|
||||
use pyo3::types::PyDict;
|
||||
use pyo3::{pyclass, pymethods, PyObject, PyResult, Python, ToPyObject};
|
||||
use pythonize::depythonize;
|
||||
@@ -80,7 +80,9 @@ impl PyZenEngine {
|
||||
trace: options.trace,
|
||||
},
|
||||
))
|
||||
.context("Failed to evaluate graph")?;
|
||||
.map_err(|e| {
|
||||
anyhow!(serde_json::to_string(e.as_ref()).unwrap_or_else(|_| e.to_string()))
|
||||
})?;
|
||||
|
||||
let value = serde_json::to_value(&result).context("Failed to serialize result")?;
|
||||
Ok(PyValue(value).to_object(py))
|
||||
|
||||
Reference in New Issue
Block a user