use std::{io, path::PathBuf};
use crate::view::NodeId;
pub type ConfigResult<T> = Result<T, ConfigError>;
#[derive(Debug, thiserror::Error)]
pub enum ConfigError {
#[error("failed to read config file `{path}`: {source}")]
ConfigRead {
path: PathBuf,
#[source]
source: io::Error,
},
#[error("invalid TOML in `{path}`{canonical_display}: {source}", canonical_display = match canonical {
Some(p) => format!(" ({})", p.display()),
None => String::new(),
})]
ConfigParse {
path: PathBuf,
canonical: Option<PathBuf>,
#[source]
source: toml::de::Error,
},
#[error("failed to resolve path `{path}`: {source}")]
PathResolve {
path: PathBuf,
#[source]
source: io::Error,
},
#[error("configuration validation failed")]
Validation,
#[error(transparent)]
RuleSet(#[from] apimock_routing::RoutingError),
}
#[derive(Debug, thiserror::Error)]
pub enum WorkspaceError {
#[error(transparent)]
Config(#[from] ConfigError),
#[error("workspace root `{path}` is not a valid apimock workspace: {reason}")]
InvalidRoot { path: PathBuf, reason: String },
}
#[derive(Debug, thiserror::Error)]
pub enum ApplyError {
#[error("unknown node id: {id}")]
UnknownNode { id: NodeId },
#[error("node {id} is not of the expected kind for this command: {reason}")]
WrongNodeKind { id: NodeId, reason: String },
#[error("invalid edit payload: {reason}")]
InvalidPayload { reason: String },
}
#[derive(Debug, thiserror::Error)]
pub enum SaveError {
#[error("failed to serialise `{path}`: {source}")]
Serialize {
path: PathBuf,
#[source]
source: toml::ser::Error,
},
#[error("failed to write `{path}`: {source}")]
Write {
path: PathBuf,
#[source]
source: io::Error,
},
#[error("internal inconsistency: {reason}")]
Inconsistent { reason: String },
}