From 0c095125de8840d09cc825dfc241b3e4d3617335 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Sun, 17 Sep 2023 02:45:17 +0400 Subject: Перенос старых наработок в новый репозиторий MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libnres/src/error.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 libnres/src/error.rs (limited to 'libnres/src/error.rs') diff --git a/libnres/src/error.rs b/libnres/src/error.rs new file mode 100644 index 0000000..440ab06 --- /dev/null +++ b/libnres/src/error.rs @@ -0,0 +1,45 @@ +extern crate miette; +extern crate thiserror; + +use miette::Diagnostic; +use thiserror::Error; + +#[derive(Error, Diagnostic, Debug)] +pub enum ConverterError { + #[error("error converting an value")] + #[diagnostic(code(libnres::infallible))] + Infallible(#[from] std::convert::Infallible), + + #[error("error converting an value")] + #[diagnostic(code(libnres::try_from_int_error))] + TryFromIntError(#[from] std::num::TryFromIntError), +} + +#[derive(Error, Diagnostic, Debug)] +pub enum ReaderError { + #[error(transparent)] + #[diagnostic(code(libnres::convert_error))] + ConvertValue(#[from] ConverterError), + + #[error("incorrect header format")] + #[diagnostic(code(libnres::list_type_error))] + IncorrectHeader, + + #[error("incorrect file size (expected {expected:?} bytes, received {received:?} bytes)")] + #[diagnostic(code(libnres::file_size_error))] + IncorrectSizeFile { expected: u32, received: u32 }, + + #[error( + "incorrect size of the file list (not a multiple of {expected:?}, received {received:?})" + )] + #[diagnostic(code(libnres::list_size_error))] + IncorrectSizeList { expected: u32, received: u32 }, + + #[error("resource file reading error")] + #[diagnostic(code(libnres::io_error))] + ReadFile(#[from] std::io::Error), + + #[error("file is too small (must be at least {expected:?} bytes, received {received:?} byte)")] + #[diagnostic(code(libnres::file_size_error))] + SmallFile { expected: u32, received: u32 }, +} -- cgit v1.2.3