From 36cc93ebee1f68c8da33a253de408fa6f487116e Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 10 Jun 2025 14:40:14 +0200 Subject: [PATCH] Graceful fail-out for when geth is unavailable --- Tools/BiblioTech/BaseGethCommand.cs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Tools/BiblioTech/BaseGethCommand.cs b/Tools/BiblioTech/BaseGethCommand.cs index 49069953..104784cc 100644 --- a/Tools/BiblioTech/BaseGethCommand.cs +++ b/Tools/BiblioTech/BaseGethCommand.cs @@ -8,9 +8,13 @@ namespace BiblioTech { protected override async Task Invoke(CommandContext context) { - var gethConnector = GethConnector.GethConnector.Initialize(Program.Log); + var gethConnector = GetGeth(); + if (gethConnector == null) + { + await context.Followup("Blockchain operations are (temporarily) unavailable."); + return; + } - if (gethConnector == null) return; var gethNode = gethConnector.GethNode; var contracts = gethConnector.CodexContracts; @@ -23,6 +27,19 @@ namespace BiblioTech await Execute(context, gethNode, contracts); } + private GethConnector.GethConnector? GetGeth() + { + try + { + return GethConnector.GethConnector.Initialize(Program.Log); + } + catch (Exception ex) + { + Program.Log.Error("Failed to initialize geth connector: " + ex); + return null; + } + } + protected abstract Task Execute(CommandContext context, IGethNode gethNode, ICodexContracts contracts); } }