Skip to content

Commit

Permalink
check node input and output (#176)
Browse files Browse the repository at this point in the history
* check node input and output

* .
  • Loading branch information
juchiast authored Nov 23, 2024
1 parent dfc9466 commit 900fd91
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
10 changes: 1 addition & 9 deletions crates/flow-server/src/db_worker/user_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,15 +490,7 @@ impl ResponseError for StartError {
flow::Error::Canceled(_) => StatusCode::INTERNAL_SERVER_ERROR,
flow::Error::ValueNotFound(_) => StatusCode::INTERNAL_SERVER_ERROR,
flow::Error::CreateCmd(_) => StatusCode::INTERNAL_SERVER_ERROR,
flow::Error::BuildGraphError(e) => match e {
flow::flow_graph::BuildGraphError::EdgesSameTarget => StatusCode::BAD_REQUEST,
flow::flow_graph::BuildGraphError::EdgeSourceNotFound(_) => {
StatusCode::BAD_REQUEST
}
flow::flow_graph::BuildGraphError::NodeNotFoundInPartialConfig(_) => {
StatusCode::BAD_REQUEST
}
},
flow::Error::BuildGraphError(_) => StatusCode::BAD_REQUEST,
flow::Error::GetFlow(e) => match e {
get_flow::Error::NotFound => StatusCode::NOT_FOUND,
get_flow::Error::Unauthorized => StatusCode::UNAUTHORIZED,
Expand Down
23 changes: 18 additions & 5 deletions crates/flow/src/flow_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,10 @@ pub enum BuildGraphError {
EdgeSourceNotFound(NodeId),
#[error("node not found in partial_config: {:?}", .0)]
NodeNotFoundInPartialConfig(NodeId),
#[error("node {:?} has no input {:?}", .0.0, .0.1)]
NoInput((NodeId, String)),
#[error("node {:?} has no output {:?}", .0.0, .0.1)]
NoOutput((NodeId, String)),
}

impl FlowGraph {
Expand Down Expand Up @@ -455,7 +459,13 @@ impl FlowGraph {
continue;
}
}
Some(n) => (n.idx, n.command.input_is_required(&to.1).unwrap_or(true)),
Some(n) => {
let required = n
.command
.input_is_required(&to.1)
.ok_or_else(|| BuildGraphError::NoInput(to.clone()))?;
(n.idx, required)
}
};
let (from_idx, optional) = match nodes.get(&from.0) {
None => {
Expand All @@ -480,10 +490,13 @@ impl FlowGraph {
continue;
}
}
Some(n) => (
n.idx,
n.command.output_is_optional(&from.1).unwrap_or(false),
),
Some(n) => {
let optional = n
.command
.output_is_optional(&from.1)
.ok_or_else(|| BuildGraphError::NoOutput(from.clone()))?;
(n.idx, optional)
}
};

g.add_edge(
Expand Down
5 changes: 5 additions & 0 deletions lib/flow-lib/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ pub trait CommandTrait: Send + Sync + 'static {
self.outputs()
.into_iter()
.find_map(|o| (o.name == name).then_some(o.optional))
.or_else(|| {
self.inputs()
.into_iter()
.find_map(|i| (i.name == name && i.passthrough).then_some(!i.required))
})
}
}

Expand Down

0 comments on commit 900fd91

Please sign in to comment.