Skip to content

Commit 6ffb322

Browse files
authored
fix(error): avoid converting non-error into PyException (#991)
1 parent 5418d7a commit 6ffb322

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

src/builder/flow_builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::{
1818
},
1919
lib_context::LibContext,
2020
ops::interface::FlowInstanceContext,
21-
py::IntoPyResult,
21+
py::{AnyhowIntoPyResult, IntoPyResult},
2222
};
2323
use crate::{lib_context::FlowContext, py};
2424

src/execution/evaluator.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use futures::future::try_join_all;
55

66
use crate::base::value::EstimatedByteSize;
77
use crate::builder::{AnalyzedTransientFlow, plan::*};
8-
use crate::py::IntoPyResult;
8+
use crate::py::AnyhowIntoPyResult;
99
use crate::{
1010
base::{schema, value},
1111
utils::immutable::RefList,
@@ -73,6 +73,7 @@ impl ScopeValueBuilder {
7373
.zip(&mut builder.fields)
7474
{
7575
r.set(augmented_value(v, &t.value_type.typ)?)
76+
.map_err(|_| anyhow!("Value of field `{}` is already set", t.name))
7677
.into_py_result()?;
7778
}
7879
Ok(builder)

src/py/convert.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use pythonize::{depythonize, pythonize};
1212
use serde::de::DeserializeOwned;
1313
use std::ops::Deref;
1414

15-
use super::IntoPyResult;
15+
use super::{AnyhowIntoPyResult, IntoPyResult};
1616

1717
#[derive(Debug)]
1818
pub struct Pythonized<T>(pub T);

src/py/mod.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,20 @@ pub trait IntoPyResult<T> {
7272
fn into_py_result(self) -> PyResult<T>;
7373
}
7474

75-
impl<T, E: std::fmt::Debug> IntoPyResult<T> for Result<T, E> {
75+
impl<T, E: std::error::Error> IntoPyResult<T> for Result<T, E> {
76+
fn into_py_result(self) -> PyResult<T> {
77+
match self {
78+
Ok(value) => Ok(value),
79+
Err(err) => Err(PyException::new_err(format!("{err:?}"))),
80+
}
81+
}
82+
}
83+
84+
pub trait AnyhowIntoPyResult<T> {
85+
fn into_py_result(self) -> PyResult<T>;
86+
}
87+
88+
impl<T> AnyhowIntoPyResult<T> for anyhow::Result<T> {
7689
fn into_py_result(self) -> PyResult<T> {
7790
match self {
7891
Ok(value) => Ok(value),

0 commit comments

Comments
 (0)