use molframe_core::{Code, diagnostic_from};
use std::path::PathBuf;
#[derive(Debug, thiserror::Error)]
pub enum DataError {
#[error("manifest {path}: {message}")]
Manifest {
path: PathBuf,
message: String,
},
#[error("manifest {path} has no entry named `{name}`")]
NoEntry {
path: PathBuf,
name: String,
},
#[error("cannot read {path}: {source}")]
Read {
path: PathBuf,
source: std::io::Error,
},
#[error("download of `{name}` failed: {source}")]
Download {
name: String,
source: molframe_adapters::DownloadError,
},
#[error("entry `{name}`: {message}")]
Convert {
name: String,
message: String,
},
#[error("{path} already exists; replace it explicitly")]
Exists {
path: PathBuf,
},
#[error("cannot write {path}: {source}")]
Write {
path: PathBuf,
source: std::io::Error,
},
}
diagnostic_from!(DataError, |error| match error {
DataError::Manifest { .. } | DataError::Convert { .. } => Code::E2201,
DataError::NoEntry { .. } => Code::E7102,
DataError::Read { .. } | DataError::Download { .. } => Code::E7101,
DataError::Exists { .. } | DataError::Write { .. } => Code::E7901,
});