@@ -96,14 +96,34 @@ public async Task<List<ScriptExecuteCommandResult>> ApplyAsync(string clusterCon
9696var clusterUrl = changeSet . To . Url ;
9797
9898var kustoHandler = KustoClusterHandlerFactory . Create ( clusterName , clusterUrl ) ;
99- var result = await kustoHandler . WriteAsync ( changeSet ) ;
100-
101- // Add the results from this cluster to the overall results list
102- allResults . AddRange ( result ) ;
99+ try
100+ {
101+ var result = await kustoHandler . WriteAsync ( changeSet ) ;
102+
103+ // Add the results from this cluster to the overall results list
104+ allResults . AddRange ( result ) ;
105+ }
106+ catch ( Exception ex )
107+ {
108+ Log . LogError ( ex , $ "Failed to apply changes to cluster:{ clusterName } ") ;
109+ allResults . Add ( CreateFailedClusterResult ( clusterName , clusterUrl , ex ) ) ;
110+ }
103111}
104112
105113Log . LogInformation ( $ "Finished applying. Total scripts executed:{ allResults . Count } ") ;
106114return allResults ;
107115}
116+
117+ private static ScriptExecuteCommandResult CreateFailedClusterResult ( string clusterName , string clusterUrl , Exception exception )
118+ {
119+ return new ScriptExecuteCommandResult
120+ {
121+ CommandType = $ "cluster-script:{ clusterName } ",
122+ OperationId = Guid . Empty ,
123+ Result = "Failed" ,
124+ Reason = $ "{ exception . GetType ( ) . Name } :{ exception . Message } ",
125+ CommandText = $ "Apply cluster '{ clusterName } ' ({ clusterUrl } )"
126+ } ;
127+ }
108128}
109129}