Skip to content

Commit 933fea1

Browse files
committed
Add allow_component_validation_failures config option
When `true`, the graph will be considered valid even if validation failed for some of the components. Signed-off-by: Sahas Subramanian <[email protected]>
1 parent abe063b commit 933fea1

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/config.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
/// Configuration options for the `ComponentGraph`.
77
#[derive(Clone, Default, Debug)]
88
pub struct ComponentGraphConfig {
9+
/// Whether to allow validation errors on components. When this is `true`,
10+
/// the graph will be built even if there are validation errors on
11+
/// components.
12+
pub allow_component_validation_failures: bool,
13+
914
/// Whether to allow unconnected components in the graph, that are not
1015
/// reachable from the root.
1116
pub allow_unconnected_components: bool,

src/graph/validation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ where
5555
] {
5656
if let Err(e) = result {
5757
errors.push(e);
58-
validation_failed = true;
58+
validation_failed = !self.config.allow_component_validation_failures;
5959
}
6060
}
6161
match errors.len() {

src/graph/validation/validate_neighbors.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ r#"InvalidGraph: Multiple validation failures:
275275
TestConnection::new(2, 3),
276276
TestConnection::new(3, 4),
277277
];
278+
// With default config, this validation fails
278279
assert!(
279280
ComponentGraph::try_new(components.clone(), connections.clone(), config.clone())
280281
.is_err_and(|e| {
@@ -283,6 +284,16 @@ r#"InvalidGraph: Multiple validation failures:
283284
)
284285
}),
285286
);
287+
// With `allow_component_validation_failures=true`, this would pass.
288+
assert!(ComponentGraph::try_new(
289+
components.clone(),
290+
connections.clone(),
291+
ComponentGraphConfig {
292+
allow_component_validation_failures: true,
293+
..config.clone()
294+
}
295+
)
296+
.is_ok());
286297

287298
components.pop();
288299
connections.pop();

0 commit comments

Comments
 (0)