tlnutil.PaymentAttemptLog: fix error formatting - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 89ddc1345d5613d0ae7621ec2d063754d2e3b158 DIR parent b6db20157079d271c8304fa1d3e6927617babce1 HTML Author: SomberNight <somber.night@protonmail.com> Date: Mon, 22 Jun 2020 03:40:04 +0200 lnutil.PaymentAttemptLog: fix error formatting fixes #6249 Diffstat: M electrum/lnonion.py | 5 +++++ M electrum/lnutil.py | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) --- DIR diff --git a/electrum/lnonion.py b/electrum/lnonion.py t@@ -405,6 +405,11 @@ class OnionRoutingFailureMessage: failure_data = failure_msg[2:] return OnionRoutingFailureMessage(failure_code, failure_data) + def code_name(self) -> str: + if isinstance(self.code, OnionFailureCode): + return str(self.code.name) + return f"Unknown error ({self.code!r})" + def construct_onion_error(reason: OnionRoutingFailureMessage, onion_packet: OnionPacket, DIR diff --git a/electrum/lnutil.py b/electrum/lnutil.py t@@ -269,8 +269,12 @@ class PaymentAttemptLog(NamedTuple): sender_idx = self.failure_details.sender_idx failure_msg = self.failure_details.failure_msg if sender_idx is not None: - short_channel_id = route[sender_idx+1].short_channel_id - message = str(failure_msg.code.name) + try: + short_channel_id = route[sender_idx + 1].short_channel_id + except IndexError: + # payment destination reported error + short_channel_id = _("Destination node") + message = failure_msg.code_name() else: short_channel_id = route[-1].short_channel_id message = _('Success')