fix: implement serializable errors; improve binding error transparency; (#62)

This commit is contained in:
stefan-gorules
2023-07-27 21:27:14 +02:00
committed by GitHub
parent 08131e5198
commit 9277850855
5 changed files with 49 additions and 6 deletions
+4 -2
View File
@@ -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))
+4 -2
View File
@@ -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))