use crate::{
fs_utils::{EscapedDisplayText, FilesystemConfigError},
plugin::PluginRegistryError,
};
use std::{io, path::PathBuf};
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum ConfigLoadError {
#[error("failed to read current directory: {source}")]
CurrentDir {
#[source]
source: io::Error,
},
#[error("failed to read config {}: {source}", display_path(path))]
Read {
path: PathBuf,
#[source]
source: io::Error,
},
#[error("failed to parse config {}: {source}", display_path(path))]
Parse {
path: PathBuf,
#[source]
source: serde_json::Error,
},
#[error("config {} failed schema validation: {message}", display_path(path))]
Schema {
path: PathBuf,
message: String,
},
#[error("failed to compile config schema: {message}")]
SchemaCompile {
message: String,
},
#[error("failed to deserialize config {}: {source}", display_path(path))]
Deserialize {
path: PathBuf,
#[source]
source: serde_json::Error,
},
#[error("config {} has invalid plugin registry: {source}", display_path(path))]
PluginRegistry {
path: PathBuf,
#[source]
source: PluginRegistryError,
},
}
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum ConfigProjectionError {
#[error("{0}")]
Filesystem(#[from] FilesystemConfigError),
}
fn display_path(path: &std::path::Path) -> String {
EscapedDisplayText::from_path(path).as_str().to_owned()
}