@@ -111,6 +111,53 @@ pub enum Error {
|
||||
/// What went wrong, short enough to log.
|
||||
detail: String,
|
||||
},
|
||||
|
||||
/// `alass` could not be started at all — the binary is not installed
|
||||
/// where the configuration points (#194). A health condition (#200),
|
||||
/// folded into the operator message §9.5 defines; never a panic.
|
||||
#[error("could not run {binary}")]
|
||||
Spawn {
|
||||
/// The binary that was attempted.
|
||||
binary: String,
|
||||
/// The underlying IO failure.
|
||||
#[source]
|
||||
source: std::io::Error,
|
||||
},
|
||||
|
||||
/// One `alass` run took longer than its timeout.
|
||||
#[error("syncing {path} timed out")]
|
||||
Timeout {
|
||||
/// The subtitle being synced.
|
||||
path: PathBuf,
|
||||
},
|
||||
|
||||
/// `alass` ran and exited non-zero.
|
||||
///
|
||||
/// Its own variant rather than [`Error::Io`]: the process answered, so
|
||||
/// this is about the sync, and `status` plus a trimmed stderr is what an
|
||||
/// operator needs to see.
|
||||
#[error("syncing {path} failed (status {status:?}): {stderr}")]
|
||||
SyncFailed {
|
||||
/// The subtitle being synced.
|
||||
path: PathBuf,
|
||||
/// The exit code, when it exited rather than died on a signal.
|
||||
status: Option<i32>,
|
||||
/// The first part of what it wrote to stderr.
|
||||
stderr: String,
|
||||
},
|
||||
|
||||
/// A file that should be SRT — the subtitle going into `alass`, or what
|
||||
/// came out of it — does not parse as SRT.
|
||||
///
|
||||
/// An implausible output is *not* here: that is [`crate::sync::Outcome::Rejected`],
|
||||
/// a decision, while a file nothing can parse is a fact worth failing on.
|
||||
#[error("{path} is not SRT: {detail}")]
|
||||
NotSrt {
|
||||
/// The file involved.
|
||||
path: PathBuf,
|
||||
/// What was wrong with it, short enough to log.
|
||||
detail: String,
|
||||
},
|
||||
}
|
||||
|
||||
impl Error {
|
||||
@@ -120,7 +167,10 @@ impl Error {
|
||||
/// response do not fix themselves, and retrying them only burns budget.
|
||||
#[must_use]
|
||||
pub const fn is_transient(&self) -> bool {
|
||||
matches!(self, Self::Transport { .. } | Self::RateLimited { .. })
|
||||
matches!(
|
||||
self,
|
||||
Self::Transport { .. } | Self::RateLimited { .. } | Self::Timeout { .. }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,4 +189,24 @@ mod tests {
|
||||
.is_transient());
|
||||
assert!(!Error::Unauthorized { provider }.is_transient());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_timeout_is_worth_retrying_and_a_missing_binary_is_not() {
|
||||
let timeout = Error::Timeout {
|
||||
path: std::path::PathBuf::from("/m/a.srt"),
|
||||
};
|
||||
let spawn = Error::Spawn {
|
||||
binary: "alass".to_owned(),
|
||||
source: std::io::Error::new(std::io::ErrorKind::NotFound, "no such file"),
|
||||
};
|
||||
let not_srt = Error::NotSrt {
|
||||
path: std::path::PathBuf::from("/m/a.srt"),
|
||||
detail: "line 1: expected a timing line".to_owned(),
|
||||
};
|
||||
assert!(timeout.is_transient());
|
||||
// A missing binary needs installing, and a broken subtitle does not
|
||||
// heal; neither resolves by retrying.
|
||||
assert!(!spawn.is_transient());
|
||||
assert!(!not_srt.is_transient());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user