use apollo_errors::Error;
use miette::Diagnostic;
use miette::SourceSpan;
use std::sync::Arc;
#[derive(Debug, Diagnostic, Error)]
#[diagnostic()]
pub(crate) enum ExpandErrorKind {
#[error("environment variable not present")]
#[diagnostic(code(apollo::configuration::env_missing))]
NotPresent {
#[label("environment variable not present")]
span: SourceSpan,
},
#[error("invalid expansion kind")]
#[diagnostic(code(apollo::configuration::env_invalid))]
#[diagnostic(help("only `env.` expansions are supported"))]
InvalidExpansion {
#[label("invalid expansion kind")]
span: SourceSpan,
},
#[error("expanded value contains invalid characters")]
#[diagnostic(code(apollo::configuration::env_invalid))]
#[diagnostic(help(
"environment variables must contain UTF-8 values to be used in configuration"
))]
NotUnicode {
#[label("could not expand this value")]
span: SourceSpan,
},
#[error("invalid bare expansion")]
#[diagnostic(code(apollo::configuration::env_invalid))]
UnprefixedExpansion {
#[label("change this to `${{env.{name}}}`")]
span: SourceSpan,
name: String,
},
}
#[derive(Debug, Diagnostic, Error)]
#[error("could not expand configuration values")]
#[diagnostic(code(apollo::configuration::expansion))]
pub struct ExpandError {
#[source_code]
pub(crate) source_code: Arc<str>,
#[related]
pub(crate) errors: Vec<ExpandErrorKind>,
}
#[derive(Debug, Error, Diagnostic)]
#[error("{message}")]
#[diagnostic(code(apollo::configuration::validation))]
pub struct ValidationError {
#[label("{message}")]
pub(crate) label: SourceSpan,
pub(crate) message: String,
}
#[derive(Debug, Error, Diagnostic)]
#[error("schema validation error")]
#[diagnostic(code(apollo::configuration::schema))]
pub struct ValidationErrors {
#[source_code]
pub(crate) source_code: Arc<str>,
#[related]
pub(crate) errors: Vec<Box<dyn Diagnostic + Send + Sync + 'static>>,
}
#[derive(Debug, Error, Diagnostic)]
pub enum YamlToJsonError {
#[error("unsupported value")]
#[diagnostic(code(apollo::configuration::invalid_number))]
InvalidNumberError {
#[source_code]
source_code: Arc<str>,
#[label("NaN/Infinity are not suported in configuration")]
label: SourceSpan,
},
#[error("unsupported key")]
#[diagnostic(code(apollo::configuration::invalid_mapping))]
InvalidMappingError {
#[source_code]
source_code: Arc<str>,
#[label("non-string mapping keys are not supported in configuration")]
label: SourceSpan,
},
}
#[derive(Debug, Error, Diagnostic)]
#[non_exhaustive]
pub enum ConfigError {
#[error("{error}")]
#[diagnostic(code(apollo::configuration::parse))]
ParseError {
#[from]
error: serde_yaml::Error,
},
#[error("{error}")]
#[diagnostic(code(apollo::configuration::parse))]
ParseError2 {
#[from]
error: saphyr::ScanError,
},
#[error("failed to parse value: {error}")]
#[diagnostic(code(apollo::configuration::parse))]
InvalidValue {
#[source_code]
source_code: Arc<str>,
#[label("this value could not be parsed")]
label: Option<SourceSpan>,
error: serde_json::Error,
},
#[error(transparent)]
#[diagnostic(transparent)]
ValidationError(#[from] ValidationErrors),
#[error(transparent)]
#[diagnostic(transparent)]
JsonConversionError(#[from] YamlToJsonError),
#[error(transparent)]
#[diagnostic(transparent)]
ExpansionError(#[from] ExpandError),
}