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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
use miette::Diagnostic;
use starbase_styles::{Style, Stylize};
use std::path::PathBuf;
use thiserror::Error;

#[derive(Debug, Diagnostic, Error)]
pub enum WarpgateError {
    #[error("{0}")]
    Serde(String),

    #[diagnostic(code(plugin::http))]
    #[error("Failed to make HTTP request.")]
    Http {
        #[source]
        error: reqwest::Error,
    },

    #[diagnostic(code(plugin::source::file_missing))]
    #[error("Cannot load plugin, source file {} does not exist.", .0.style(Style::Url))]
    SourceFileMissing(PathBuf),

    #[diagnostic(code(plugin::github::asset_missing))]
    #[error(
        "Cannot download plugin from GitHub ({}), no applicable asset found for release {}.",
        .repo_slug.style(Style::Id),
        .tag,
    )]
    GitHubAssetMissing { repo_slug: String, tag: String },

    #[diagnostic(code(plugin::wapm::module_missing))]
    #[error(
        "Cannot download plugin from wamp.io ({}), no applicable module found for release {}.",
        .package.style(Style::Id),
        .version,
    )]
    WapmModuleMissing { package: String, version: String },

    #[diagnostic(code(plugin::create::failed))]
    #[error("Failed to load and create WASM plugin.")]
    PluginCreateFailed {
        #[source]
        error: extism::Error,
    },

    #[diagnostic(code(plugin::call_func::failed))]
    #[error("Failed to call plugin function {}.", .func.style(Style::Id))]
    PluginCallFailed {
        func: String,
        #[source]
        error: extism::Error,
    },

    #[diagnostic(code(plugin::call_func::format_input))]
    #[error("Failed to format input for plugin function {} call.", .func.style(Style::Id))]
    FormatInputFailed {
        func: String,
        #[source]
        error: serde_json::Error,
    },

    #[diagnostic(code(plugin::call_func::parse_output))]
    #[error("Failed to parse output of plugin function {} call.", .func.style(Style::Id))]
    ParseOutputFailed {
        func: String,
        #[source]
        error: serde_json::Error,
    },

    #[diagnostic(
        code(plugin::download::missing),
        help = "Please refer to the plugin's official documentation."
    )]
    #[error("Plugin download {} does not exist. This version may not be supported for your current operating system or architecture, or the URL is incorrect.", .url.style(Style::Url))]
    DownloadNotFound { url: String },

    #[diagnostic(code(plugin::download::failed))]
    #[error("Failed to download plugin from {} ({status}).", .url.style(Style::Url))]
    DownloadFailed { url: String, status: String },
}