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
use colored::Colorize;
use core::fmt::Display;

pub enum RswErr {
    WasmPack,
    Config(std::io::Error),
    ParseToml(toml::de::Error),
    WatchFile(notify::Error),
    Crate(String, std::io::Error),
}

impl Display for RswErr {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            RswErr::WasmPack => {
                write!(f,
                    "{} wasm-pack {}\nCannot find wasm-pack in your PATH. Please make sure wasm-pack is installed.",
                    "[⚙️ rsw::env]".red().on_black(),
                    "https://github.com/rustwasm/wasm-pack".green(),
                )
            }
            RswErr::Config(_err) => {
                write!(
                    f,
                    "{} {} must exist in the project root path.",
                    "[⚙️ rsw.toml]".red().on_black(),
                    "rsw.toml".yellow(),
                    // _err,
                )
            }
            RswErr::ParseToml(err) => {
                write!(f, "{} {}", "[⚙️ rsw.toml]".red().on_black(), err)
            }
            RswErr::WatchFile(e) => {
                write!(
                    f,
                    "{} Error while trying to watch the files:\n\t{}",
                    "[🦀 rsw::crate]".red().on_black(),
                    e
                )
            }
            RswErr::Crate(name, err) => {
                write!(
                    f,
                    "{} {} {}",
                    "[🦀 rsw::crate]".red().on_black(),
                    name.yellow(),
                    err
                )
            }
        }
    }
}