rustronomy_fits/err/io_err.rs
1/*
2 Copyright (C) 2022 Raúl Wolters
3
4 This file is part of rustronomy-fits.
5
6 rustronomy is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 rustronomy is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with rustronomy. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20use std::{
21 error::Error,
22 fmt::{self, Display, Formatter},
23};
24
25#[derive(Debug)]
26pub struct InvalidFitsFileErr {
27 /*
28 This error may be thrown when opening a FITS file. If the FITS
29 file has invalid encoding (for whatever reason), this error will be
30 thrown.
31 */
32 msg: &'static str,
33}
34
35//Possible messages
36pub(crate) const FILE_BLOCK_DIV: &'static str =
37 "tried to open file with a length not equal to an integer multiple of FITS blocks";
38pub(crate) const BUF_BLOCK_DIV: &'static str =
39 "supplied buffer not an integer multiple of FITS blocks";
40pub(crate) const FILE_END: &'static str = "tried to read more FITS blocks than the file contains";
41pub(crate) const CORRUPTED: &'static str = "tried to access corrupted data";
42
43impl Error for InvalidFitsFileErr {}
44impl Display for InvalidFitsFileErr {
45 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
46 write!(f, "Error while accessing FITS file: {}", self.msg)
47 }
48}
49
50impl InvalidFitsFileErr {
51 pub(crate) fn new(msg: &'static str) -> Self {
52 InvalidFitsFileErr { msg: msg }
53 }
54}