use thiserror::Error;
use marlu::{fitsio, io::error::BadArrayShape, mwalib, mwalib::FitsError};
#[derive(Error, Debug)]
#[allow(clippy::upper_case_acronyms)]
pub enum IOError {
#[error("{source_file}:{source_line}\nInvalid flag filename template. Must contain \"%%\" (or \"%%%\") for MWAX")]
InvalidFlagFilenameTemplate {
source_file: &'static str,
source_line: u32,
filename_template: String,
},
#[error("{source_file}:{source_line}\nCouldn't open {fits_filename}: {fits_error}")]
FitsOpen {
fits_error: fitsio::errors::Error,
fits_filename: String,
source_file: &'static str,
source_line: u32,
},
#[error("{source_file}:{source_line}\n{fits_filename} HDU {hdu_num}: {fits_error}")]
#[allow(clippy::upper_case_acronyms)]
FitsIO {
fits_error: fitsio::errors::Error,
fits_filename: String,
hdu_num: usize,
source_file: &'static str,
source_line: u32,
},
#[error(transparent)]
FitsError(#[from] mwalib::FitsError),
#[error(transparent)]
FitsioError(#[from] fitsio::errors::Error),
#[error(transparent)]
MarluIOError(#[from] marlu::io::error::IOError),
#[error(transparent)]
UvfitsWriteError(#[from] marlu::io::error::UvfitsWriteError),
#[error("Attempted to finalise mwaf files with {count} rows, but {expected} were expected")]
MwafIncorrectFlagCount {
count: u64,
expected: u64,
},
#[error(transparent)]
BadArrayShape(#[from] BadArrayShape),
#[error(transparent)]
IO(#[from] std::io::Error),
}
#[derive(Error, Debug)]
pub enum ReadSolutionsError {
#[error("Tried to read calibration solutions file with an unsupported extension '{ext}'!")]
#[allow(missing_docs)]
UnsupportedExt { ext: String },
#[error(
"When reading {file}, expected MWAOCAL as the first 7 characters, got '{got}' instead!"
)]
#[allow(missing_docs)]
AndreBinaryStr { file: String, got: String },
#[error(
"When reading {file}, expected a value {expected} in the header, but got '{got}' instead!"
)]
#[allow(missing_docs)]
AndreBinaryVal {
file: String,
expected: &'static str,
got: String,
},
#[error("In file {file} key {key}, could not parse '{got}' as a number!")]
#[allow(missing_docs)]
Parse {
file: String,
key: &'static str,
got: String,
},
#[error(transparent)]
#[allow(missing_docs)]
Fits(#[from] FitsError),
#[error("IO error: {0}")]
#[allow(missing_docs)]
IO(#[from] std::io::Error),
}