|
|
|
use std::{
|
|
|
|
fmt::{Debug, Display, Formatter},
|
|
|
|
path::PathBuf,
|
|
|
|
};
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum Error {
|
|
|
|
IOError(Box<dyn std::error::Error>),
|
|
|
|
InvalidObjectType(u32),
|
|
|
|
InvalidSectionName,
|
|
|
|
InvalidSectionData,
|
|
|
|
ParseError(Box<dyn std::error::Error>),
|
|
|
|
TryFromIntError, //
|
|
|
|
LinkingError(Trace),
|
|
|
|
}
|
|
|
|
|
|
|
|
// "backtrace" for error origin
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Trace {
|
|
|
|
origin: PathBuf,
|
|
|
|
offset: u64, // 0 indicates unknown/invalid
|
|
|
|
source_info: Option<Box<dyn SourceInfo>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait SourceInfo: Debug + Display {
|
|
|
|
fn line(&self) -> u64;
|
|
|
|
|
|
|
|
// todo
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<std::io::Error> for Error {
|
|
|
|
fn from(err: std::io::Error) -> Self {
|
|
|
|
Self::IOError(Box::new(err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<std::num::TryFromIntError> for Error {
|
|
|
|
fn from(err: std::num::TryFromIntError) -> Self {
|
|
|
|
Self::TryFromIntError
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Display for Error {
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
|
|
write!(f, "TODO!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Display for Trace {
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
|
|
write!(f, "TODO!")
|
|
|
|
}
|
|
|
|
}
|