use std::fmt;
use std::path::PathBuf;
use crate::report::display_path;
use crate::schema::{EnumType, Table};
#[derive(Debug, Clone)]
pub struct TableFailure {
pub table: String,
pub reason: String,
pub path: Option<PathBuf>,
pub line: Option<usize>,
pub schema: Option<String>,
pub last_good: Option<Box<LastGood>>,
}
#[derive(Debug, Clone)]
pub struct LastGood {
pub table: Table,
pub enums: Vec<EnumType>,
}
impl LastGood {
pub fn new(table: Table) -> Box<Self> {
Box::new(Self {
table,
enums: Vec::new(),
})
}
}
impl fmt::Display for TableFailure {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let (Some(path), Some(line)) = (&self.path, self.line) {
write!(f, "{}:{line}: ", display_path(path))?;
}
write!(f, "table `{}`: {}", self.table, self.reason)
}
}