aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/package/loader/invalid_package_exception.rs
blob: 2325199475b0304199ba66af92a92a597a6a1bd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//! ref: composer/src/Composer/Package/Loader/InvalidPackageException.php

use indexmap::IndexMap;
use shirabe_php_shim::{Exception, PhpMixed};

#[derive(Debug)]
pub struct InvalidPackageException {
    inner: Exception,
    errors: Vec<String>,
    warnings: Vec<String>,
    data: IndexMap<String, PhpMixed>,
}

impl InvalidPackageException {
    pub fn new(
        errors: Vec<String>,
        warnings: Vec<String>,
        data: IndexMap<String, PhpMixed>,
    ) -> Self {
        let message = format!(
            "Invalid package information: \n{}",
            errors
                .iter()
                .chain(warnings.iter())
                .cloned()
                .collect::<Vec<_>>()
                .join("\n")
        );
        Self {
            inner: Exception::new(message),
            errors,
            warnings,
            data,
        }
    }

    pub fn get_data(&self) -> &IndexMap<String, PhpMixed> {
        &self.data
    }

    pub fn get_errors(&self) -> &[String] {
        &self.errors
    }

    pub fn get_warnings(&self) -> &[String] {
        &self.warnings
    }
}

shirabe_php_shim::impl_php_exception!(
    InvalidPackageException,
    inner,
    r"Composer\Package\Loader\InvalidPackageException"
);