use crate::error::Error;
const NOT_FOUND: &str = "release: not found";
const IN_PROGRESS: &str = "another operation (install/upgrade/rollback) is in progress";
const TIMEOUTS: [&str; 2] = [
"context deadline exceeded",
"timed out waiting for the condition",
];
pub(super) fn classify(exit_code: Option<i32>, stderr: String) -> Error {
let message = stderr
.lines()
.rev()
.find_map(|line| line.strip_prefix("Error: "))
.unwrap_or_else(|| stderr.trim())
.to_owned();
if stderr.contains(NOT_FOUND) {
return Error::ReleaseNotFound(message);
}
if stderr.contains(IN_PROGRESS) {
return Error::OperationInProgress(message);
}
if TIMEOUTS.iter().any(|t| stderr.contains(t)) {
return Error::Timeout(message);
}
Error::Backend { exit_code, stderr }
}