summaryrefslogtreecommitdiffstats
path: root/src/error.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs51
1 files changed, 48 insertions, 3 deletions
diff --git a/src/error.rs b/src/error.rs
index ac47fc8..cf6e567 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -68,11 +68,56 @@ impl Error {
Error::Transient(s.to_string())
}
- /// True when a retry could plausibly help (network, mirror 5xx). Deterministic
- /// build failures must not auto-retry (§8.4).
+ /// True when a retry could plausibly help (§8.4): an unreachable upstream, a
+ /// mirror that 5xx'd, a connection that reset.
+ ///
+ /// `Error::Io` is *not* automatically transient (m-14). `ENOSPC` and
+ /// `EACCES` are `Io`, and treating them as retryable meant a full disk or a
+ /// misconfigured root turned into three identical failures, a shrug, and a
+ /// build that never got the operator's attention. Only the kinds that mean
+ /// "the same call might work in a moment" are retried.
pub fn is_transient(&self) -> bool {
- matches!(self, Error::Http(_) | Error::Io(_) | Error::Transient(_))
+ match self {
+ Error::Http(_) | Error::Transient(_) => true,
+ Error::Io(e) => matches!(
+ e.kind(),
+ std::io::ErrorKind::WouldBlock
+ | std::io::ErrorKind::TimedOut
+ | std::io::ErrorKind::Interrupted
+ | std::io::ErrorKind::BrokenPipe
+ | std::io::ErrorKind::ConnectionReset
+ | std::io::ErrorKind::ConnectionRefused
+ | std::io::ErrorKind::ConnectionAborted
+ ),
+ _ => false,
+ }
}
}
pub type Result<T> = std::result::Result<T, Error>;
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn a_full_disk_is_not_a_retryable_failure() {
+ // m-14: `Error::Io` used to mean "retry", so ENOSPC and EACCES — both
+ // plain `Io` — turned into three identical failures and a build that
+ // never announced itself as broken.
+ let enospc = Error::Io(std::io::Error::from_raw_os_error(28));
+ let eacces = Error::Io(std::io::Error::from_raw_os_error(13));
+ assert!(!enospc.is_transient(), "a full disk does not clear itself between retries");
+ assert!(!eacces.is_transient(), "a permissions problem does not clear itself either");
+ }
+
+ #[test]
+ fn what_a_moment_might_fix_is_retried() {
+ let refused = Error::Io(std::io::Error::from_raw_os_error(111));
+ assert!(refused.is_transient());
+ assert!(Error::transient("mirror returned 502").is_transient());
+ assert!(Error::Http("connection reset".into()).is_transient());
+ assert!(!Error::invalid("recipe has no pkgbase").is_transient());
+ assert!(!Error::fail_closed("identity hash moved").is_transient());
+ }
+}