From e19644ae8cf0acf7bd21eec2a609f76cb6810293 Mon Sep 17 00:00:00 2001 From: pythcoiner Date: Wed, 12 Mar 2025 03:43:57 +0100 Subject: [PATCH] gui: display export error --- liana-gui/src/app/error.rs | 2 +- liana-gui/src/app/view/warning.rs | 2 +- liana-gui/src/backup.rs | 9 ++++++++- liana-gui/src/export.rs | 22 ++++++++++++++++++++++ 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/liana-gui/src/app/error.rs b/liana-gui/src/app/error.rs index 4c5cee82..dad8c47c 100644 --- a/liana-gui/src/app/error.rs +++ b/liana-gui/src/app/error.rs @@ -60,7 +60,7 @@ impl std::fmt::Display for Error { Self::Unexpected(e) => write!(f, "Unexpected error: {}", e), Self::HardwareWallet(e) => write!(f, "error: {}\nPlease check if the device is still connected and unlocked with the correct firmware open for the current network and no other application is accessing the device.", e), Self::Desc(e) => write!(f, "Liana descriptor error: {}", e), - Self::ImportExport(e) => write!(f, "{e:?}"), + Self::ImportExport(e) => write!(f, "{e}"), } } } diff --git a/liana-gui/src/app/view/warning.rs b/liana-gui/src/app/view/warning.rs index 4af3fabe..011ed430 100644 --- a/liana-gui/src/app/view/warning.rs +++ b/liana-gui/src/app/view/warning.rs @@ -49,7 +49,7 @@ impl From<&Error> for WarningMessage { Error::HardwareWallet(_) => WarningMessage("Hardware wallet error".to_string()), Error::Desc(e) => WarningMessage(format!("Descriptor analysis error: '{}'.", e)), Error::Spend(e) => WarningMessage(format!("Spend creation error: '{}'.", e)), - Error::ImportExport(e) => WarningMessage(format!("{e:?}")), + Error::ImportExport(e) => WarningMessage(format!("{e}")), } } } diff --git a/liana-gui/src/backup.rs b/liana-gui/src/backup.rs index a3ca2c48..c11150cd 100644 --- a/liana-gui/src/backup.rs +++ b/liana-gui/src/backup.rs @@ -74,7 +74,14 @@ pub enum Error { impl Display for Error { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{self:?}") + match self { + Error::DescriptorMissing => write!(f, "Backup: descriptor missing"), + Error::NotSingleWallet => write!(f, "Backup: Zero or several wallets"), + Error::Json => write!(f, "Backup: json error"), + Error::SettingsFromFile => write!(f, "Backup: fail to parse setting from file"), + Error::Daemon(e) => write!(f, "Backup daemon error: {e}"), + Error::TxTimeMissing => write!(f, "Backup: transaction block height missing"), + } } } diff --git a/liana-gui/src/export.rs b/liana-gui/src/export.rs index 7bdf7e8d..77026043 100644 --- a/liana-gui/src/export.rs +++ b/liana-gui/src/export.rs @@ -1,5 +1,6 @@ use std::{ collections::HashMap, + fmt::Display, fs::{self, File}, io::{Read, Write}, path::PathBuf, @@ -156,6 +157,27 @@ pub enum Error { Backup(backup::Error), } +impl Display for Error { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Error::Io(e) => write!(f, "ImportExport Io Error: {e}"), + Error::HandleLost => write!(f, "ImportExport: subprocess handle lost"), + Error::UnexpectedEnd => write!(f, "ImportExport: unexpected end of the process"), + Error::JoinError(e) => write!(f, "ImportExport fail to handle.join(): {e} "), + Error::ChannelLost => write!(f, "ImportExport: the channel have been closed"), + Error::NoParentDir => write!(f, "ImportExport: there is no parent dir"), + Error::Daemon(e) => write!(f, "ImportExport daemon error: {e}"), + Error::TxTimeMissing => write!(f, "ImportExport: transaction block height missing"), + Error::DaemonMissing => write!(f, "ImportExport: the daemon is missing"), + Error::ParsePsbt => write!(f, "ImportExport: fail to parse PSBT"), + Error::ParseDescriptor => write!(f, "ImportExport: fail to parse descriptor"), + Error::Bip329Export(e) => write!(f, "Bip329Export: {e}"), + Error::BackupImport(e) => write!(f, "BackupImport: {e}"), + Error::Backup(e) => write!(f, "Backup: {e}"), + } + } +} + #[derive(Debug, Clone)] pub enum ImportExportType { Transactions,