diff options
Diffstat (limited to 'src/watch')
| -rw-r--r-- | src/watch/detect.rs | 4 | ||||
| -rw-r--r-- | src/watch/mirror.rs | 6 | ||||
| -rw-r--r-- | src/watch/sources.rs | 10 | ||||
| -rw-r--r-- | src/watch/upstream.rs | 4 |
4 files changed, 13 insertions, 11 deletions
diff --git a/src/watch/detect.rs b/src/watch/detect.rs index 82539b8..3d2c955 100644 --- a/src/watch/detect.rs +++ b/src/watch/detect.rs @@ -1,6 +1,6 @@ use crate::config::Config; use crate::db::{self, *}; -use crate::error::Result; +use crate::error::{Missing, Result}; use crate::pkgver; use crate::recipe::recipe_from_tree; use crate::review::candidates::{NewCandidate, Upsert}; @@ -31,7 +31,7 @@ pub struct CheckReport { pub fn check_pkgbase(cfg: &Config, db: &Db, name: &str) -> Result<CheckReport> { let pb = get_pkgbase(db, name)? - .ok_or_else(|| crate::error::Error::not_found(format!("pkgbase {name}")))?; + .ok_or_else(|| crate::error::Error::not_found(Missing::Pkgbase(name.to_string())))?; let sub = db::get_subscription(db, name)?; let paused = sub.as_ref().map(|s| s.state == SubscriptionState::Paused).unwrap_or(false); if paused { diff --git a/src/watch/mirror.rs b/src/watch/mirror.rs index 6616bc1..924eb52 100644 --- a/src/watch/mirror.rs +++ b/src/watch/mirror.rs @@ -3,7 +3,7 @@ use std::path::Path; use crate::config::Config; use crate::db::{self, Db}; -use crate::error::{Error, Result}; +use crate::error::{Error, Missing, Result}; use crate::git; #[derive(Debug, Clone, PartialEq, Eq)] @@ -41,7 +41,7 @@ pub fn sync_mirror(cfg: &Config, db: &Db, name: &str, url: &str) -> Result<Sync> } fn record(db: &Db, name: &str, head: &str, mirror: &Path) -> Result<()> { - let pb = db::get_pkgbase(db, name)?.ok_or_else(|| Error::not_found(format!("pkgbase {name}")))?; + let pb = db::get_pkgbase(db, name)?.ok_or_else(|| Error::not_found(Missing::Pkgbase(name.to_string())))?; db::set_aur_head(&db.writer, pb.id, head, &mirror.display().to_string()) } @@ -89,7 +89,7 @@ pub fn read_tree(mirror: &Path, commit: &str) -> Result<Tree> { for (path, sha) in &blobs { let bytes = contents .get(sha) - .ok_or_else(|| Error::not_found(format!("{path} not in mirror")))?; + .ok_or_else(|| Error::not_found(Missing::MirrorPath(path.to_string())))?; if bytes.len() > 4 * 1024 * 1024 || !looks_textual(bytes) { continue; } diff --git a/src/watch/sources.rs b/src/watch/sources.rs index 7b56774..9767cef 100644 --- a/src/watch/sources.rs +++ b/src/watch/sources.rs @@ -15,7 +15,7 @@ use std::path::Path; use crate::config::Config; use crate::db::Db; -use crate::error::{Error, Result}; +use crate::error::{Error, Guard, Result}; use crate::watch::digests::{cached_path, download_and_cache}; use crate::watch::mirror::read_tree; @@ -36,9 +36,11 @@ pub fn verify_cached(cfg: &Config, db: &Db, url: &str, digest: &str) -> Result<( None => download_and_cache(cfg, db, url)?.0, }; if found != digest { - return Err(Error::fail_closed(format!( - "source {url} hashed to {found} but the candidate recorded {digest}" - ))); + return Err(Error::fail_closed(Guard::DigestMismatch { + url: url.to_string(), + expected: digest.to_string(), + found, + })); } Ok(()) } diff --git a/src/watch/upstream.rs b/src/watch/upstream.rs index 2b89238..1af1488 100644 --- a/src/watch/upstream.rs +++ b/src/watch/upstream.rs @@ -6,7 +6,7 @@ use std::sync::{Condvar, Mutex}; use crate::config::Config; use crate::db::{self, model::*, Db, Pkgbase}; -use crate::error::{Error, Result}; +use crate::error::{Error, Result, TransientCause}; use crate::git; #[derive(Debug, Clone)] @@ -185,7 +185,7 @@ fn run( let cache = cfg.vcs_cache_path(&pin.url); if !cache.exists() { git::clone_bare(&pin.url, &cache) - .map_err(|e| Error::transient(format!("vcs_cache clone {}: {e}", pin.url)))?; + .map_err(|e| Error::transient(TransientCause::Upstream(format!("vcs_cache clone {}: {e}", pin.url))))?; } else { let _ = git::fetch_and_head(&cache); } |
