Error messages instead of unreachable

Currently this code is actually not reachable, but that is semantically applied by the program's flow (the resume command includes the swap direction).
It is still preferred to have an error message rather than an unreachable statement.
pull/147/head
Daniel Karzel 4 years ago
parent 2dceab28a4
commit 41e335fc2d

@ -1,6 +1,6 @@
//! Run an XMR/BTC swap in the role of Alice.
//! Alice holds XMR and wishes receive BTC.
use anyhow::Result;
use anyhow::{bail, Result};
use libp2p::{request_response::ResponseChannel, NetworkBehaviour, PeerId};
use tracing::{debug, info};
@ -131,7 +131,10 @@ impl SwapFactory {
let resume_state = if let database::Swap::Alice(state) = db.get_state(self.swap_id)? {
state.into()
} else {
unreachable!()
bail!(
"Trying to load swap with id {} for the wrong direction.",
self.swap_id
)
};
let (event_loop, event_loop_handle) = init_alice_event_loop(

@ -1,6 +1,6 @@
//! Run an XMR/BTC swap in the role of Bob.
//! Bob holds BTC and wishes receive XMR.
use anyhow::Result;
use anyhow::{bail, Result};
use libp2p::{core::Multiaddr, NetworkBehaviour, PeerId};
use tracing::{debug, info};
@ -133,7 +133,10 @@ impl SwapFactory {
let resume_state = if let database::Swap::Bob(state) = db.get_state(self.swap_id)? {
state.into()
} else {
unreachable!()
bail!(
"Trying to load swap with id {} for the wrong direction.",
self.swap_id
)
};
let (event_loop, event_loop_handle) = init_bob_event_loop(

Loading…
Cancel
Save