#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DiagKind {
Overlap { start: u64, len: u64 },
Gap { start: u64, len: u64 },
Truncated { start: u64, want: u64, have: u64 },
ChainCycle { at_offset: u64 },
BackwardChainLink { from: u64, to: u64 },
DataHashMismatch { uid: [u8; 16] },
TableHashMismatch { block_index: usize },
EntryInvalid { uid: [u8; 16], reason: String },
BadHeader { reason: String },
BadBlock { offset: u64, reason: String },
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Severity {
Info,
Warning,
Error,
}
impl Severity {
pub fn tag(self) -> &'static str {
match self {
Severity::Info => "INFO",
Severity::Warning => "WARN",
Severity::Error => "ERROR",
}
}
}
#[derive(Debug, Clone)]
pub struct Diagnostic {
pub severity: Severity,
pub kind: DiagKind,
pub message: String,
}
impl Diagnostic {
pub fn info(kind: DiagKind, message: impl Into<String>) -> Self {
Self {
severity: Severity::Info,
kind,
message: message.into(),
}
}
pub fn warn(kind: DiagKind, message: impl Into<String>) -> Self {
Self {
severity: Severity::Warning,
kind,
message: message.into(),
}
}
pub fn error(kind: DiagKind, message: impl Into<String>) -> Self {
Self {
severity: Severity::Error,
kind,
message: message.into(),
}
}
}