use thiserror::Error;
pub type Result<T> = std::result::Result<T, HaoError>;
#[derive(Error, Debug)]
pub enum HaoError {
#[error("An IO error has occored. {0:?}")]
IoError(std::io::Error),
#[error("failed to parse PE file")]
BadPeFormat,
#[error("PE error: {0:?}")]
PeError(pewter::error::PewterError),
#[error("file is not a .net binary")]
NotDotNetBinary,
#[error("file is badly formatted. {0}")]
BadImageFormat(&'static str),
#[error("RVA {0} is too large for this image")]
BadRva(u32),
#[error("Not enough data to complete read of {0} bytes")]
NotEnoughDataLeft(usize),
#[error("Invalid column size: {0}")]
InvalidColumnSize(i32),
#[error("Invalid value ({0}) for coded token \"{1}\".")]
InvalidCodedToken(u32, &'static str),
#[error("Invalid offset ({0}) for coded token \"{1}\".")]
InvalidCodedTokenOffset(u32, &'static str),
#[error("Invalid index ({0}) for stream \"{1}\".")]
InvalidStreamIndex(&'static str, usize),
#[error("Invalid UTF8 string at position {0} in #Strings stream. ({1:?})")]
InvalidUTF8String(usize, Vec<u8>),
#[error("Invalid signature calling convention. {0}.")]
InvalidSignatureCallingConvention(u8),
#[error("Invalid signature element type ({0:#x}) at position {1}.")]
InvalidSignatureElementType(u8, usize),
#[error("Invalid signature: {0} (at position {1}).")]
InvalidSignature(&'static str, usize),
#[error("Invalid method body: {0} (at position {1}).")]
InvalidMethodBody(&'static str, usize),
#[error("Invalid opcode {0:#x} at position {1}.")]
InvalidOpCode(u16, usize),
#[error("Invalid metadata token {0:#010x}.")]
InvalidToken(u32),
#[error("Invalid custom attribute: {0}")]
InvalidCustomAttribute(String),
#[error("Value too large to encode as a {0}.")]
ValueTooLarge(&'static str),
#[error("Could not write module: {0}")]
WriteError(String),
#[error("The provided signature does not match what is expected for the entry.")]
InvalidSignatureForEntry(&'static str),
#[error("Recursion limit reached.")]
RecursionLimitReached,
#[error("Invalid reference to entry in {0} table at index {1}.")]
InvalidEntryRefrence(&'static str, usize),
#[error("unknown error")]
Unknown,
}