vivacity-core 0.15.0

Manifests, content hash, platform checks, dist fetching, content-addressed store and installation for vivacity
Documentation
use std::path::{Path, PathBuf};

#[derive(Debug, thiserror::Error)]
pub enum Error {
    #[error("failed to read {path}: {source}")]
    ReadFile {
        path: PathBuf,
        #[source]
        source: std::io::Error,
    },

    #[error("I/O error at {path}: {source}")]
    Io {
        path: PathBuf,
        #[source]
        source: std::io::Error,
    },

    #[error("invalid JSON in {context}: {source}")]
    Json {
        context: String,
        #[source]
        source: serde_json::Error,
    },

    #[error("invalid zip archive for {dest}: {source}")]
    Zip {
        dest: PathBuf,
        #[source]
        source: zip::result::ZipError,
    },

    #[error("hostile archive refused for {dest}: {reason}")]
    HostileArchive { dest: PathBuf, reason: String },

    #[error("HTTP failure for {url}: {message}")]
    Http { url: String, message: String },

    #[error("dist checksum mismatch for {name}: expected sha1 {expected}, got {actual}")]
    ShasumMismatch {
        name: String,
        expected: String,
        actual: String,
    },

    #[error("cannot encode non-finite float ({0}) as JSON (PHP json_encode would fail too)")]
    NonFiniteFloat(f64),

    /// Plugin emulation that cannot be reproduced byte for byte, detected
    /// before any change to vendor/: the CLI delegates to Composer.
    #[error("{0}")]
    Unsupported(String),

    /// A refusal Composer states in its own words (`PathDownloader`):
    /// printed as is, exit 1.
    #[error("{0}")]
    Refused(String),
}

impl Error {
    pub fn io(path: &Path) -> impl FnOnce(std::io::Error) -> Error + '_ {
        move |source| Error::Io {
            path: path.to_path_buf(),
            source,
        }
    }

    pub fn zip(dest: &Path) -> impl FnOnce(zip::result::ZipError) -> Error + '_ {
        move |source| Error::Zip {
            dest: dest.to_path_buf(),
            source,
        }
    }
}

pub type Result<T> = std::result::Result<T, Error>;