1use crate::config_error::ProtoConfigError;
2use crate::layout::ProtoLayoutError;
3use starbase_styles::{Style, Stylize};
4use std::path::PathBuf;
5use thiserror::Error;
6use warpgate::{Id, WarpgateClientError, WarpgatePluginError};
7
8#[derive(Error, Debug, miette::Diagnostic)]
9pub enum ProtoToolError {
10 #[diagnostic(transparent)]
11 #[error(transparent)]
12 Client(#[from] Box<WarpgateClientError>),
13
14 #[diagnostic(transparent)]
15 #[error(transparent)]
16 Config(#[from] Box<ProtoConfigError>),
17
18 #[diagnostic(transparent)]
19 #[error(transparent)]
20 Layout(#[from] Box<ProtoLayoutError>),
21
22 #[diagnostic(transparent)]
23 #[error(transparent)]
24 Plugin(#[from] Box<WarpgatePluginError>),
25
26 #[diagnostic(code(proto::tool::minimum_version_requirement))]
27 #[error(
28 "Unable to use the {tool} plugin with identifier {}, as it requires a minimum proto version of {}, but found {} instead.",
29 .id.to_string().style(Style::Id),
30 .expected.style(Style::Hash),
31 .actual.style(Style::Hash)
32 )]
33 InvalidMinimumVersion {
34 tool: String,
35 id: Id,
36 expected: String,
37 actual: String,
38 },
39
40 #[diagnostic(code(proto::tool::invalid_inventory_dir))]
41 #[error("{tool} inventory directory has been overridden with {} but it's not an absolute path. Only absolute paths are supported.", .dir.style(Style::Path))]
42 RequiredAbsoluteInventoryDir { tool: String, dir: PathBuf },
43}
44
45impl From<WarpgateClientError> for ProtoToolError {
46 fn from(e: WarpgateClientError) -> ProtoToolError {
47 ProtoToolError::Client(Box::new(e))
48 }
49}
50
51impl From<ProtoConfigError> for ProtoToolError {
52 fn from(e: ProtoConfigError) -> ProtoToolError {
53 ProtoToolError::Config(Box::new(e))
54 }
55}
56
57impl From<ProtoLayoutError> for ProtoToolError {
58 fn from(e: ProtoLayoutError) -> ProtoToolError {
59 ProtoToolError::Layout(Box::new(e))
60 }
61}
62
63impl From<WarpgatePluginError> for ProtoToolError {
64 fn from(e: WarpgatePluginError) -> ProtoToolError {
65 ProtoToolError::Plugin(Box::new(e))
66 }
67}