Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/builder/flow_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{
},
lib_context::LibContext,
ops::interface::FlowInstanceContext,
py::IntoPyResult,
py::{AnyhowIntoPyResult, IntoPyResult},
};
use crate::{lib_context::FlowContext, py};

Expand Down
3 changes: 2 additions & 1 deletion src/execution/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use futures::future::try_join_all;

use crate::base::value::EstimatedByteSize;
use crate::builder::{AnalyzedTransientFlow, plan::*};
use crate::py::IntoPyResult;
use crate::py::AnyhowIntoPyResult;
use crate::{
base::{schema, value},
utils::immutable::RefList,
Expand Down Expand Up @@ -73,6 +73,7 @@ impl ScopeValueBuilder {
.zip(&mut builder.fields)
{
r.set(augmented_value(v, &t.value_type.typ)?)
.map_err(|_| anyhow!("Value of field `{}` is already set", t.name))
.into_py_result()?;
}
Ok(builder)
Expand Down
2 changes: 1 addition & 1 deletion src/py/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use pythonize::{depythonize, pythonize};
use serde::de::DeserializeOwned;
use std::ops::Deref;

use super::IntoPyResult;
use super::{AnyhowIntoPyResult, IntoPyResult};

#[derive(Debug)]
pub struct Pythonized<T>(pub T);
Expand Down
15 changes: 14 additions & 1 deletion src/py/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,20 @@ pub trait IntoPyResult<T> {
fn into_py_result(self) -> PyResult<T>;
}

impl<T, E: std::fmt::Debug> IntoPyResult<T> for Result<T, E> {
impl<T, E: std::error::Error> IntoPyResult<T> for Result<T, E> {
fn into_py_result(self) -> PyResult<T> {
match self {
Ok(value) => Ok(value),
Err(err) => Err(PyException::new_err(format!("{err:?}"))),
}
}
}

pub trait AnyhowIntoPyResult<T> {
fn into_py_result(self) -> PyResult<T>;
}

impl<T> AnyhowIntoPyResult<T> for anyhow::Result<T> {
fn into_py_result(self) -> PyResult<T> {
match self {
Ok(value) => Ok(value),
Expand Down
Loading