From 9b73acab6e2b40524eafaa867fae5977d9f46c6c Mon Sep 17 00:00:00 2001 From: librelois <c@elo.tf> Date: Tue, 15 Dec 2020 20:22:36 +0100 Subject: [PATCH] [ref] dbs: open_dbs must return a result --- rust-bins/duniter-dbex/src/migrate.rs | 2 +- rust-libs/duniter-dbs/src/open_dbs.rs | 13 +++++-------- rust-libs/duniter-server/src/lib.rs | 2 +- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/rust-bins/duniter-dbex/src/migrate.rs b/rust-bins/duniter-dbex/src/migrate.rs index b7d249987..65a76b96b 100644 --- a/rust-bins/duniter-dbex/src/migrate.rs +++ b/rust-bins/duniter-dbex/src/migrate.rs @@ -26,7 +26,7 @@ const CHUNK_SIZE: usize = 250; pub(crate) fn migrate(profile_path: PathBuf) -> anyhow::Result<()> { let start_time = Instant::now(); - let (bc_db, shared_dbs) = duniter_dbs::open_dbs(Some(profile_path.as_path())); + let (bc_db, shared_dbs) = duniter_dbs::open_dbs(Some(profile_path.as_path()))?; let gva_db = duniter_gva_db_writer::get_gva_db_rw(Some(profile_path.as_path())); // Clear bc_db and gva_db diff --git a/rust-libs/duniter-dbs/src/open_dbs.rs b/rust-libs/duniter-dbs/src/open_dbs.rs index 04ae6264a..f20687b47 100644 --- a/rust-libs/duniter-dbs/src/open_dbs.rs +++ b/rust-libs/duniter-dbs/src/open_dbs.rs @@ -21,12 +21,11 @@ use crate::*; pub fn open_dbs<B: BackendConf>( profile_path_opt: Option<&Path>, -) -> (crate::databases::bc_v2::BcV2Db<B>, SharedDbs<B>) { +) -> KvResult<(crate::databases::bc_v2::BcV2Db<B>, SharedDbs<B>)> { let bc_db = crate::databases::bc_v2::BcV2Db::<B>::open(B::gen_backend_conf( crate::databases::bc_v2::BcV2Db::<B>::NAME, profile_path_opt, - )) - .expect("fail to open BcV2 DB"); + ))?; let dbs = SharedDbs { bc_db_ro: bc_db.get_ro_handler(), cm_db: crate::databases::cm_v1::CmV1Db::<Mem>::open(MemConf::default()) @@ -34,15 +33,13 @@ pub fn open_dbs<B: BackendConf>( dunp_db: crate::databases::dunp_v1::DunpV1Db::<B>::open(B::gen_backend_conf( "dunp_v1", profile_path_opt, - )) - .expect("fail to open Dunp DB"), + ))?, txs_mp_db: crate::databases::txs_mp_v2::TxsMpV2Db::<B>::open(B::gen_backend_conf( crate::databases::txs_mp_v2::TxsMpV2Db::<B>::NAME, profile_path_opt, - )) - .expect("fail to open TxsMp DB"), + ))?, }; - (bc_db, dbs) + Ok((bc_db, dbs)) } pub trait BackendConf: Backend { diff --git a/rust-libs/duniter-server/src/lib.rs b/rust-libs/duniter-server/src/lib.rs index 8235de295..795f8930b 100644 --- a/rust-libs/duniter-server/src/lib.rs +++ b/rust-libs/duniter-server/src/lib.rs @@ -115,7 +115,7 @@ impl DuniterServer { let txs_mempool = TxsMempool::new(conf.txs_mempool_size); log::info!("open duniter databases..."); - let (bc_db, dbs) = duniter_dbs::open_dbs(profile_path_opt); + let (bc_db, dbs) = duniter_dbs::open_dbs(profile_path_opt)?; dbs.dunp_db.heads_old_write().clear()?; // Clear WS2Pv1 HEADs log::info!("Databases successfully opened."); let current = duniter_dbs_read_ops::get_current_block_meta(&dbs.bc_db_ro) -- GitLab