use std::sync::Arc;
#[derive(Debug, thiserror::Error, miette::Diagnostic, Clone)]
#[non_exhaustive]
pub enum UpdateError {
#[error(transparent)]
#[diagnostic(transparent)]
Provider(#[from] rtb_forge::ProviderError),
#[error("no asset found for target {target}")]
#[diagnostic(
code(rtb::update::no_matching_asset),
help("the release exists but has no asset for this platform; a rebuild may be needed")
)]
NoMatchingAsset {
target: String,
},
#[error("asset signature file missing (expected `{asset}.sig` or `{asset}.minisig`)")]
#[diagnostic(
code(rtb::update::missing_signature),
help(
"every published release must ship a detached signature; re-run the release pipeline"
)
)]
MissingSignature {
asset: String,
},
#[error("signature verification failed for `{asset}`")]
#[diagnostic(
code(rtb::update::bad_signature),
help(
"the downloaded bytes do not match the vendor's public key — treat as a potential tampering event"
)
)]
BadSignature {
asset: String,
},
#[error("SHA-256 checksum mismatch for `{asset}`")]
#[diagnostic(code(rtb::update::bad_checksum))]
BadChecksum {
asset: String,
},
#[error("downloaded binary failed the runnable-self-test")]
#[diagnostic(
code(rtb::update::self_test_failed),
help("the new binary refused `--version`; refusing to swap")
)]
SelfTestFailed,
#[error("atomic swap failed: {0}")]
#[diagnostic(code(rtb::update::swap_failed))]
SwapFailed(String),
#[error("tool metadata carries no release source; update disabled")]
#[diagnostic(code(rtb::update::no_source))]
NoReleaseSource,
#[error("tool metadata carries no public key; signatures cannot be verified")]
#[diagnostic(
code(rtb::update::no_public_key),
help("populate `ToolMetadata::update_public_keys` at compile time")
)]
NoPublicKey,
#[error("downgrade refused: target {target} is older than current {current}")]
#[diagnostic(
code(rtb::update::downgrade_refused),
help("pass `--force` to explicitly downgrade")
)]
DowngradeRefused {
target: semver::Version,
current: semver::Version,
},
#[error("archive extraction failed: {0}")]
#[diagnostic(code(rtb::update::archive))]
Archive(String),
#[error("asset pattern invalid or unmatched: {0}")]
#[diagnostic(code(rtb::update::pattern))]
Pattern(String),
#[error("I/O error: {0}")]
#[diagnostic(code(rtb::update::io))]
Io(#[from] Arc<std::io::Error>),
}
impl From<std::io::Error> for UpdateError {
fn from(err: std::io::Error) -> Self {
Self::Io(Arc::new(err))
}
}
pub type Result<T> = std::result::Result<T, UpdateError>;