Skip to content

Commit 18e99de

Browse files
committed
Throw the last exception in case of retry over
1 parent 76512b5 commit 18e99de

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

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

Lines changed: 8 additions & 3 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 ScalarDbClusterSample.Commands;
@@ -16,6 +17,7 @@ public static Command Create()
1617
using var sample = new Sample();
1718
await sample.CreateTables();
1819

20+
TransactionException? lastException = null;
1921
var attempts = 10;
2022
while (attempts-- > 0)
2123
{
@@ -24,17 +26,20 @@ 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
});
37-
42+
3843
return loadInitialDataCommand;
3944
}
4045
}

0 commit comments

Comments
 (0)