Skip to content

Commit fb51789

Browse files
author
François Delbrayelle
committed
fix: use onInvalidSyntax properly when invalid flows
1 parent 54ca47c commit fb51789

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/main/java/io/kestra/plugin/git/TenantSync.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public Output run(RunContext runContext) throws Exception {
242242
}
243243
}
244244

245-
List<FlowWithSource> kestraFlows = fetchFlowsFromKestra(kestraClient, runContext, namespace);
245+
List<FlowWithSource> kestraFlows = fetchFlowsFromKestra(kestraClient, runContext, namespace, rOnInvalidSyntax);
246246
Map<String, byte[]> kestraFiles = listNamespaceFiles(kestraClient, runContext, namespace);
247247

248248
planNamespace(
@@ -728,7 +728,7 @@ private void planDashboards(
728728
}
729729
}
730730

731-
private List<FlowWithSource> fetchFlowsFromKestra(KestraClient kestraClient, RunContext runContext, String namespace) {
731+
private List<FlowWithSource> fetchFlowsFromKestra(KestraClient kestraClient, RunContext runContext, String namespace, OnInvalidSyntax rOnInvalidSyntax) {
732732
try {
733733
// Export all flows from Kestra for the given namespace (including sub-namespaces)
734734
byte[] zippedFlows = kestraClient.flows().exportFlowsByQuery(
@@ -748,9 +748,16 @@ private List<FlowWithSource> fetchFlowsFromKestra(KestraClient kestraClient, Run
748748
continue;
749749
}
750750

751-
String yaml = new String(zis.readAllBytes(), StandardCharsets.UTF_8);
751+
var entryName = entry.getName();
752+
var yaml = new String(zis.readAllBytes(), StandardCharsets.UTF_8);
752753

753-
io.kestra.core.models.flows.Flow parsed = io.kestra.core.serializers.YamlParser.parse(yaml, io.kestra.core.models.flows.Flow.class);
754+
io.kestra.core.models.flows.Flow parsed;
755+
try {
756+
parsed = io.kestra.core.serializers.YamlParser.parse(yaml, io.kestra.core.models.flows.Flow.class);
757+
} catch (Exception e) {
758+
handleInvalid(runContext, rOnInvalidSyntax, "FLOW from entry " + entryName, e);
759+
continue;
760+
}
754761

755762
if (!namespace.equals(parsed.getNamespace())) {
756763
continue;
@@ -762,6 +769,9 @@ private List<FlowWithSource> fetchFlowsFromKestra(KestraClient kestraClient, Run
762769

763770
return flows;
764771

772+
} catch (KestraRuntimeException e) {
773+
// Re-throw KestraRuntimeException from handleInvalid(FAIL) without wrapping
774+
throw e;
765775
} catch (Exception e) {
766776
throw new KestraRuntimeException("Failed to export flows from Kestra for namespace " + namespace, e);
767777
}

0 commit comments

Comments
 (0)