diff options
Diffstat (limited to 'src/db')
| -rw-r--r-- | src/db/candidates.rs | 6 | ||||
| -rw-r--r-- | src/db/releases.rs | 8 | ||||
| -rw-r--r-- | src/db/repos.rs | 4 |
3 files changed, 8 insertions, 10 deletions
diff --git a/src/db/candidates.rs b/src/db/candidates.rs index df145ac..10d39bf 100644 --- a/src/db/candidates.rs +++ b/src/db/candidates.rs @@ -1,7 +1,7 @@ use rusqlite::{params, OptionalExtension, Row, Transaction}; use crate::db::{CandidateRow, CandidateState, Db}; -use crate::error::{Error, Result}; +use crate::error::{Error, Missing, Refused, Result}; use crate::time; const CANDIDATE_COLS: &str = "c.id, c.pkgbase_id, c.base_release_id, c.kind, c.snapshot_id, c.epoch, c.pkgver, \ @@ -123,8 +123,8 @@ pub fn resolve_in(tx: &Transaction<'_>, id: i64, to: CandidateState, at: &str) - .query_row("SELECT state FROM candidate WHERE id=?1", params![id], |r| r.get(0)) .optional()?; return Err(match was { - Some(w) => Error::conflict(format!("illegal candidate transition {w} → {to} for review {id}")), - None => Error::not_found(format!("no candidate {id} to resolve")), + Some(w) => Error::conflict(Refused::IllegalTransition { entity: "candidate", id: id.to_string(), from: w, to: to.to_string() }), + None => Error::not_found(Missing::Candidate(id)), }); } Ok(()) diff --git a/src/db/releases.rs b/src/db/releases.rs index cf1502a..cff31c1 100644 --- a/src/db/releases.rs +++ b/src/db/releases.rs @@ -1,7 +1,7 @@ use rusqlite::{params, OptionalExtension, Row}; use crate::db::*; -use crate::error::{Error, Result}; +use crate::error::{Error, Missing, Refused, Result}; // ---------------------------------------------------------------- release -- @@ -41,10 +41,8 @@ pub fn withdraw_release_in(tx: &rusqlite::Transaction<'_>, release_id: i64) -> R .query_row("SELECT state FROM release WHERE id=?1", params![release_id], |r| r.get(0)) .optional()?; return Err(match state.as_deref().map(ReleaseState::parse) { - None => Error::not_found(format!("no release {release_id}")), - Some(Some(s)) => Error::conflict(format!( - "release {release_id} is {s}, not published: nothing to withdraw" - )), + None => Error::not_found(Missing::Release(release_id)), + Some(Some(s)) => Error::conflict(Refused::WrongState { entity: "release", id: release_id.to_string(), found: s.to_string(), expected: "published" }), Some(None) => Error::invalid(format!( "release {release_id} has a state outside the state machine: {:?}", state.unwrap_or_default() diff --git a/src/db/repos.rs b/src/db/repos.rs index 14acce1..1906610 100644 --- a/src/db/repos.rs +++ b/src/db/repos.rs @@ -1,7 +1,7 @@ use rusqlite::{params, OptionalExtension}; use crate::db::*; -use crate::error::{Error, Result}; +use crate::error::{Error, Missing, Result}; // -------------------------------------------------------------------- repo -- @@ -23,7 +23,7 @@ pub fn repo_id(db: &Db) -> Result<i64> { db.read(|c| { c.query_row("SELECT id FROM repo ORDER BY id LIMIT 1", [], |r| r.get(0)) .optional()? - .ok_or_else(|| Error::not_found("no repo row; run `aur-build init`")) + .ok_or_else(|| Error::not_found(Missing::RepoRow)) }) } |
