1use std::io::Error as IoError;
2use thiserror::Error;
3use image::ImageError;
4
5use crate::{
6 loading::{MapDataLoadingError, ProvincesMapLoadingError},
7 map::PredefinedRegionsLoadingError,
8};
9
10#[derive(Error, Debug)]
11pub enum Error {
12 #[error("failed to load map data: {0}")]
13 MapDataLoadingFailed(#[from] MapDataLoadingError),
14 #[error("failed to load provinces map: {0}")]
15 ProvincesMapLoadingFailed(#[from] ProvincesMapLoadingError),
16 #[error("failed to load predefined regions map: {0}")]
17 PredefinedRegionsLoadingFailed(#[from] PredefinedRegionsLoadingError),
18 #[error("failed to process image: {0}")]
19 ImageError(#[from] ImageError),
20 #[error("failed to write metadata file: {0}")]
21 MetadataWritingFailed(#[source] IoError)
22}
23
24impl Error {
25 pub fn from_write_metadata_error(io_error: IoError) -> Self {
26 Self::MetadataWritingFailed(io_error)
27 }
28
29 pub fn eprint_encountered_map_data_errors(&self) {
30 if let Self::MapDataLoadingFailed(MapDataLoadingError::InvalidMapData(map_data_errors)) = self {
31 for map_data_error in map_data_errors {
32 eprintln!("{}", map_data_error);
33 }
34 }
35 }
36}