RPC error handling (eg edge not found)

This commit is contained in:
Djuri Baars 2021-10-02 23:13:19 +02:00
parent 4c1a0822f0
commit 8d65bc7677
2 changed files with 17 additions and 8 deletions

View file

@ -38,6 +38,9 @@ def format_channel(channel, node1_alias, node2_alias, chanDisabled, show_fees):
else: else:
return text return text
def format_channel_error(channelID, error):
text = f'{channelID:<18} ERROR: {error:<100}'
return chalk.bg_red(text)
def clear_screen(): def clear_screen():
os.system('cls' if os.name == 'nt' else 'clear') os.system('cls' if os.name == 'nt' else 'clear')

View file

@ -1,7 +1,8 @@
import os import os
import grpc
from time import sleep from time import sleep
from output import format_error, clear_screen, format_channel from output import format_channel_error, format_error, clear_screen, format_channel
LOOP_SLEEP_TIME = 10 LOOP_SLEEP_TIME = 10
@ -41,11 +42,16 @@ class Status:
if not channelID.isnumeric(): if not channelID.isnumeric():
continue continue
response = self.lnd.get_edge(int(channelID)) try:
node1 = self.lnd.get_node(response.node1_pub) response = self.lnd.get_edge(int(channelID))
node2 = self.lnd.get_node(response.node2_pub) node1 = self.lnd.get_node(response.node1_pub)
disabled = response.node1_policy.disabled or response.node2_policy.disabled node2 = self.lnd.get_node(response.node2_pub)
self.print_channel(response, node1.alias, node2.alias, disabled) disabled = response.node1_policy.disabled or response.node2_policy.disabled
self.print_channel(response, node1.alias, node2.alias, disabled)
except grpc.RpcError as e:
self.output.print_line(format_channel_error(channelID, e.details()))
except Exception as error:
self.output.print_line(format_channel_error(channelID, repr(error)))
def print_channel(self, channel, node1_alias, node2_alias, chan_disabled): def print_channel(self, channel, node1_alias, node2_alias, chan_disabled):
self.output.print_line(format_channel(channel, node1_alias, node2_alias, chan_disabled, self.show_fees)) self.output.print_line(format_channel(channel, node1_alias, node2_alias, chan_disabled, self.show_fees))