helm-rs 0.1.0

Typed Rust API for Helm 4: swappable backends, native chart, values and release reading
Documentation
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",
];

/// Maps a failed run to a typed error from Helm's stderr, falling back to [`Error::Backend`]
/// (which keeps the raw stderr). The messages come from `pkg/storage/driver/driver.go`,
/// `pkg/action/action.go` and the Go runtime.
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 }
}