Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check node input and output #176

Merged
merged 2 commits into from
Nov 23, 2024
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
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
Loading