Skip to content

Commit 0e7cd46

Browse files
committed
Throw the last exception when the retry is over
1 parent 032c119 commit 0e7cd46

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

scalardb-dotnet-samples/scalardb-cluster-sql-sample/Commands/LoadInitialDataCommand.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.CommandLine;
2+
using System.Diagnostics;
23
using ScalarDB.Client.Exceptions;
34

45
namespace ScalarDbClusterSqlSample.Commands;
@@ -16,6 +17,7 @@ public static Command Create()
1617
using var sample = new Sample();
1718
await sample.CreateTables();
1819

20+
IllegalArgumentException? lastException = null;
1921
var attempts = 10;
2022
while (attempts-- > 0)
2123
{
@@ -24,15 +26,18 @@ public static Command Create()
2426
await sample.LoadInitialData();
2527
return;
2628
}
27-
catch (IllegalArgumentException)
29+
catch (IllegalArgumentException ex)
2830
{
2931
// there's can be a lag until ScalarDB Cluster recognize namespaces and tables created
3032
// in some databases like Cassandra, so if this command was called for the first time
3133
// the first attempts can fail with 'The namespace does not exist' error
32-
34+
lastException = ex;
3335
await Task.Delay(TimeSpan.FromSeconds(1));
3436
}
3537
}
38+
39+
Debug.Assert(lastException != null);
40+
throw lastException;
3641
});
3742

3843
return loadInitialDataCommand;

0 commit comments

Comments
 (0)