installer: clean unwraps and add logs to final step
GUI should handle failure gracefully with logs instead of crashing.
This commit is contained in:
parent
88e5977166
commit
4131ee529d
2
gui/Cargo.lock
generated
2
gui/Cargo.lock
generated
@ -1640,7 +1640,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "liana"
|
||||
version = "0.2.0"
|
||||
source = "git+https://github.com/wizardsardine/liana?branch=master#66e37a2cdf489308d2aeb6a8bf509fd71f68c5ef"
|
||||
source = "git+https://github.com/wizardsardine/liana?branch=master#88e5977166373437169ea00e54f365085afd03c0"
|
||||
dependencies = [
|
||||
"backtrace",
|
||||
"base64",
|
||||
|
||||
@ -138,7 +138,19 @@ impl Installer {
|
||||
data_dir.push(self.context.bitcoin_config.network.to_string());
|
||||
// In case of failure during install, block the thread to
|
||||
// deleted the data_dir/network directory in order to start clean again.
|
||||
std::fs::remove_dir_all(data_dir).expect("Correctly deleted");
|
||||
log::warn!("Installation failed. Cleaning up the leftover data directory.");
|
||||
if let Err(e) = std::fs::remove_dir_all(&data_dir) {
|
||||
log::error!(
|
||||
"Failed to completely delete the data directory (path: '{}'): {}",
|
||||
data_dir.to_string_lossy(),
|
||||
e
|
||||
);
|
||||
} else {
|
||||
log::warn!(
|
||||
"Successfully deleted data directory at '{}'.",
|
||||
data_dir.to_string_lossy()
|
||||
);
|
||||
};
|
||||
self.steps
|
||||
.get_mut(self.current)
|
||||
.expect("There is always a step")
|
||||
@ -161,13 +173,25 @@ impl Installer {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn install(ctx: Context) -> Result<PathBuf, Error> {
|
||||
let mut cfg: liana::config::Config = ctx.extract_daemon_config();
|
||||
pub fn daemon_check(cfg: liana::config::Config) -> Result<(), Error> {
|
||||
// Start Daemon to check correctness of installation
|
||||
let daemon = liana::DaemonHandle::start_default(cfg.clone()).map_err(|e| {
|
||||
Error::Unexpected(format!("Failed to start daemon with entered config: {}", e))
|
||||
})?;
|
||||
daemon.shutdown();
|
||||
match liana::DaemonHandle::start_default(cfg) {
|
||||
Ok(daemon) => {
|
||||
daemon.shutdown();
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => Err(Error::Unexpected(format!(
|
||||
"Failed to start Liana daemon: {}",
|
||||
e
|
||||
))),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn install(ctx: Context) -> Result<PathBuf, Error> {
|
||||
log::info!("installing");
|
||||
let mut cfg: liana::config::Config = ctx.extract_daemon_config();
|
||||
daemon_check(cfg.clone())?;
|
||||
log::info!("daemon checked");
|
||||
|
||||
cfg.data_dir =
|
||||
Some(cfg.data_dir.unwrap().canonicalize().map_err(|e| {
|
||||
@ -178,8 +202,8 @@ pub async fn install(ctx: Context) -> Result<PathBuf, Error> {
|
||||
datadir_path.push(cfg.bitcoin_config.network.to_string());
|
||||
|
||||
// Step needed because of ValueAfterTable error in the toml serialize implementation.
|
||||
let daemon_config =
|
||||
toml::Value::try_from(&cfg).expect("daemon::Config has a proper Serialize implementation");
|
||||
let daemon_config = toml::Value::try_from(&cfg)
|
||||
.map_err(|e| Error::Unexpected(format!("Failed to serialize daemon config: {}", e)))?;
|
||||
|
||||
// create lianad configuration file
|
||||
let daemon_config_path = create_and_write_file(
|
||||
@ -188,6 +212,8 @@ pub async fn install(ctx: Context) -> Result<PathBuf, Error> {
|
||||
daemon_config.to_string().as_bytes(),
|
||||
)?;
|
||||
|
||||
log::info!("Daemon config file created");
|
||||
|
||||
// create liana GUI configuration file
|
||||
let gui_config_path = create_and_write_file(
|
||||
datadir_path.clone(),
|
||||
@ -197,18 +223,24 @@ pub async fn install(ctx: Context) -> Result<PathBuf, Error> {
|
||||
Error::Unexpected(format!("Failed to canonicalize daemon config path: {}", e))
|
||||
})?,
|
||||
))
|
||||
.unwrap()
|
||||
.map_err(|e| Error::Unexpected(format!("Failed to serialize gui config: {}", e)))?
|
||||
.as_bytes(),
|
||||
)?;
|
||||
|
||||
log::info!("Gui config file created");
|
||||
|
||||
// create liana GUI settings file
|
||||
let settings: gui_settings::Settings = ctx.extract_gui_settings();
|
||||
create_and_write_file(
|
||||
datadir_path,
|
||||
gui_settings::DEFAULT_FILE_NAME,
|
||||
serde_json::to_string_pretty(&settings).unwrap().as_bytes(),
|
||||
serde_json::to_string_pretty(&settings)
|
||||
.map_err(|e| Error::Unexpected(format!("Failed to serialize settings: {}", e)))?
|
||||
.as_bytes(),
|
||||
)?;
|
||||
|
||||
log::info!("Settings file created");
|
||||
|
||||
Ok(gui_config_path)
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user