Skip to content

Commit 36cc93e

Browse files
committed
Graceful fail-out for when geth is unavailable
1 parent c5ff76d commit 36cc93e

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

Tools/BiblioTech/BaseGethCommand.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ public abstract class BaseGethCommand : BaseCommand
88
{
99
protected override async Task Invoke(CommandContext context)
1010
{
11-
var gethConnector = GethConnector.GethConnector.Initialize(Program.Log);
11+
var gethConnector = GetGeth();
12+
if (gethConnector == null)
13+
{
14+
await context.Followup("Blockchain operations are (temporarily) unavailable.");
15+
return;
16+
}
1217

13-
if (gethConnector == null) return;
1418
var gethNode = gethConnector.GethNode;
1519
var contracts = gethConnector.CodexContracts;
1620

@@ -23,6 +27,19 @@ protected override async Task Invoke(CommandContext context)
2327
await Execute(context, gethNode, contracts);
2428
}
2529

30+
private GethConnector.GethConnector? GetGeth()
31+
{
32+
try
33+
{
34+
return GethConnector.GethConnector.Initialize(Program.Log);
35+
}
36+
catch (Exception ex)
37+
{
38+
Program.Log.Error("Failed to initialize geth connector: " + ex);
39+
return null;
40+
}
41+
}
42+
2643
protected abstract Task Execute(CommandContext context, IGethNode gethNode, ICodexContracts contracts);
2744
}
2845
}

0 commit comments

Comments
 (0)