From abb9560b6de23dd326aaba160539b7dda1363a8f Mon Sep 17 00:00:00 2001 From: benbierens Date: Mon, 23 Oct 2023 15:49:14 +0200 Subject: [PATCH] Better logging of k8s exceptions --- .../KubernetesWorkflow/StartupWorkflow.cs | 31 ++++++++++++++----- .../CodexContractsStarter.cs | 4 +-- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/Framework/KubernetesWorkflow/StartupWorkflow.cs b/Framework/KubernetesWorkflow/StartupWorkflow.cs index 3cf59a1..c8635d4 100644 --- a/Framework/KubernetesWorkflow/StartupWorkflow.cs +++ b/Framework/KubernetesWorkflow/StartupWorkflow.cs @@ -1,4 +1,5 @@ using Logging; +using Newtonsoft.Json; using Utils; namespace KubernetesWorkflow @@ -195,17 +196,33 @@ namespace KubernetesWorkflow private void K8s(Action action) { - var controller = new K8sController(log, cluster, knownK8SPods, numberSource, k8sNamespace); - action(controller); - controller.Dispose(); + try + { + var controller = new K8sController(log, cluster, knownK8SPods, numberSource, k8sNamespace); + action(controller); + controller.Dispose(); + } + catch (k8s.Autorest.HttpOperationException ex) + { + log.Error(JsonConvert.SerializeObject(ex)); + throw; + } } private T K8s(Func action) { - var controller = new K8sController(log, cluster, knownK8SPods, numberSource, k8sNamespace); - var result = action(controller); - controller.Dispose(); - return result; + try + { + var controller = new K8sController(log, cluster, knownK8SPods, numberSource, k8sNamespace); + var result = action(controller); + controller.Dispose(); + return result; + } + catch (k8s.Autorest.HttpOperationException ex) + { + log.Error(JsonConvert.SerializeObject(ex)); + throw; + } } } diff --git a/ProjectPlugins/CodexContractsPlugin/CodexContractsStarter.cs b/ProjectPlugins/CodexContractsPlugin/CodexContractsStarter.cs index ea8fe4b..60a7104 100644 --- a/ProjectPlugins/CodexContractsPlugin/CodexContractsStarter.cs +++ b/ProjectPlugins/CodexContractsPlugin/CodexContractsStarter.cs @@ -33,9 +33,9 @@ namespace CodexContractsPlugin { return DeployContract(container, workflow, gethNode); } - catch + catch (Exception ex) { - Log("Failed to deploy contract."); + Log("Failed to deploy contract: " + ex); Log("Downloading Codex SmartContracts container log..."); ci.DownloadLog(container); throw;