diff options
| author | aur-build <aur-build@localhost> | 2026-11-17 20:59:57 +0000 |
|---|---|---|
| committer | aur-build <aur-build@localhost> | 2026-11-17 20:59:57 +0000 |
| commit | fd3ecf91686b11feea078531baeddb60e6941116 (patch) | |
| tree | 7e76c0d8a2041bf0d8d227939db9e55ea5b2afb5 /src/error.rs | |
| parent | 3762c7ce9f765283f47e5716b708e04590339375 (diff) | |
| download | aur-build-fd3ecf91686b11feea078531baeddb60e6941116.tar.gz aur-build-fd3ecf91686b11feea078531baeddb60e6941116.zip | |
feat: SQLite schema, migrations, single writer actor
The §11 data model as four migrations, plus the §11a concurrency model:
one writer thread owning the write connection (mutations arrive as
closures over a crossbeam channel, so SQLITE_BUSY is not part of the
design) and thread-local read-only connections under WAL.
Invariants that are database guarantees rather than conventions:
I7 partial unique index -> at most one pending_review per pkgbase
I3 UNIQUE(pkgbase_id, identity_hash) -> no duplicate candidates
I10 audit table rejects UPDATE and DELETE by trigger
§16 current_accepted_release_id moves only by compare-and-swap
Also: vercmp + dependency-string parsing (ALPM algorithm, no libalpm),
hash helpers including recipe_hash over the whole AUR tree, the clock
helper that stamps every write, and the config/root layout.
Part of P0 (DESIGN.md §17).
Diffstat (limited to 'src/error.rs')
| -rw-r--r-- | src/error.rs | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..a60843c --- /dev/null +++ b/src/error.rs @@ -0,0 +1,70 @@ +//! Error type shared across the application. + +use std::fmt; + +#[derive(Debug, thiserror::Error)] +pub enum Error { + #[error("io: {0}")] + Io(#[from] std::io::Error), + #[error("json: {0}")] + Json(#[from] serde_json::Error), + #[error("sqlite: {0}")] + Db(String), + #[error("sqlite: {0}")] + Sqlite(#[from] rusqlite::Error), + #[error("git: {0}")] + Git(String), + #[error("http fetch: {0}")] + Http(String), + #[error("child process {cmd}: {detail}")] + Subprocess { cmd: String, detail: String }, + /// A fail-closed assertion. Everything that guards "we build what we reviewed" + /// raises this: recipe_hash mismatch, pkgver mismatch, missing approval. + #[error("assertion failed: {0}")] + FailClosed(String), + #[error("not found: {0}")] + NotFound(String), + #[error("conflict: {0}")] + Conflict(String), + #[error("invalid: {0}")] + Invalid(String), + #[error("blocked: {0}")] + Blocked(String), + #[error("{0}")] + Other(String), +} + +impl Error { + pub fn db(s: impl fmt::Display) -> Self { + Error::Db(s.to_string()) + } + pub fn git(s: impl fmt::Display) -> Self { + Error::Git(s.to_string()) + } + pub fn fail_closed(s: impl fmt::Display) -> Self { + Error::FailClosed(s.to_string()) + } + pub fn not_found(s: impl fmt::Display) -> Self { + Error::NotFound(s.to_string()) + } + pub fn conflict(s: impl fmt::Display) -> Self { + Error::Conflict(s.to_string()) + } + pub fn invalid(s: impl fmt::Display) -> Self { + Error::Invalid(s.to_string()) + } + pub fn blocked(s: impl fmt::Display) -> Self { + Error::Blocked(s.to_string()) + } + pub fn other(s: impl fmt::Display) -> Self { + Error::Other(s.to_string()) + } + + /// True when a retry could plausibly help (network, mirror 5xx). Deterministic + /// build failures must not auto-retry (§8.4). + pub fn is_transient(&self) -> bool { + matches!(self, Error::Http(_) | Error::Io(_)) + } +} + +pub type Result<T> = std::result::Result<T, Error>; |
