update a cuople error messages

This commit is contained in:
Igor Katson 2024-04-29 17:40:44 +01:00
parent 82f8b0932c
commit 867785422c
2 changed files with 13 additions and 3 deletions

View file

@ -55,6 +55,16 @@ pub enum ManagedTorrentState {
}
impl ManagedTorrentState {
pub fn name(&self) -> &'static str {
match self {
ManagedTorrentState::Initializing(_) => "initializing",
ManagedTorrentState::Paused(_) => "paused",
ManagedTorrentState::Live(_) => "live",
ManagedTorrentState::Error(_) => "error",
ManagedTorrentState::None => "<invalid: none>",
}
}
fn assert_paused(self) -> TorrentStatePaused {
match self {
Self::Paused(paused) => paused,

View file

@ -300,9 +300,9 @@ impl ManagedTorrent {
let files = match s {
crate::ManagedTorrentState::Paused(p) => &p.files,
crate::ManagedTorrentState::Live(l) => &l.files,
_ => anyhow::bail!("invalid state"),
s => anyhow::bail!("with_opened_file: invalid state {}", s.name()),
};
let fd = files.get(file_id).context("invalid file")?;
let fd = files.get(file_id).context("invalid file id")?;
Ok(f(fd))
})
}
@ -311,7 +311,7 @@ impl ManagedTorrent {
self.with_state(|s| match s {
crate::ManagedTorrentState::Paused(p) => Ok(p.streams.clone()),
crate::ManagedTorrentState::Live(l) => Ok(l.streams.clone()),
_ => anyhow::bail!("invalid state"),
s => anyhow::bail!("streams: invalid state {}", s.name()),
})
}