Better handle transactional errors originating from agent

This commit is contained in:
Xavier Moffett 2024-09-10 19:55:08 -04:00
parent 956f0ce176
commit 4fb2ac7ef8
Signed by: Sapphirus
GPG key ID: A6C061B2CEA1A7AC
3 changed files with 10 additions and 5 deletions

View file

@ -74,7 +74,8 @@ lazy_static! {
#[derive(Serialize, Deserialize, Clone, Debug)]
pub enum SyncError {
TransactionFailureAgent,
TransactionAgentError,
TransactionAgentFailure,
ParameterAcquisitionFailure,
DeserializationFailure,
InvalidMagicNumber,
@ -117,12 +118,15 @@ impl Display for SyncError {
Self::InternalError(msg) => write!(fmter, "Internal failure: {msg}"),
Self::SignalInterrupt => write!(fmter, "Signal interrupt was triggered."),
Self::UnableToLocateKeyrings => write!(fmter, "Unable to locate pacman keyrings."),
Self::TransactionAgentError => write!(fmter, "Agent process terminated due to upstream error."),
Self::RepoConfError(path, err) => write!(fmter, "'{}': {}", path, err),
Self::NothingToDo => write!(fmter, "Nothing to do."),
_ => Ok(()),
}?;
if let Self::SignalInterrupt = self {
if let Self::TransactionFailure(_) = self {
Ok(())
} else if let Self::SignalInterrupt = self {
write!(fmter, "\n{} Transaction aborted.", *ARROW_RED)
} else {
write!(fmter, "\n{} Transaction failed.", *ARROW_RED)

View file

@ -285,7 +285,7 @@ impl<'a> TransactionAggregator<'a> {
handle.release();
return match err.downcast::<SyncError>().map_err(|err| error!(SyncError::from(err)))? {
SyncError::TransactionFailureAgent => exit(err.kind().code()),
SyncError::TransactionAgentFailure => exit(err.kind().code()),
_ => Err(err),
};
}

View file

@ -193,7 +193,8 @@ fn wait_on_agent(mut agent: Child) -> Result<()> {
match agent.wait() {
Ok(status) => match status.code().unwrap_or(-1) {
0 => Ok(()),
2 => err!(SyncError::TransactionFailureAgent),
1 => err!(SyncError::TransactionAgentError),
2 => err!(SyncError::TransactionAgentFailure),
3 => err!(SyncError::ParameterAcquisitionFailure),
4 => err!(SyncError::DeserializationFailure),
5 => err!(SyncError::InvalidMagicNumber),