use derive_more::{Display, Error};
use uuid::Uuid;
#[derive(Debug, Clone, PartialEq, Eq, Hash, Display)]
pub enum UomErrorKind {
#[display("unknown unit '{}' for '{}'", unit, registration)]
UnknownUnit {
unit: String,
registration: String,
},
#[display("quantity '{}' not found", id)]
NotFound {
id: Uuid,
},
#[display("operation requires same registration, got '{}' and '{}'", lhs, rhs)]
HomogeneousRequired {
lhs: String,
rhs: String,
},
#[display(
"dimension derivation failed: '{}' {} '{}' has no known result",
lhs,
op,
rhs
)]
UnknownDerivation {
lhs: String,
op: String,
rhs: String,
},
#[display("serialisation error: {}", msg)]
Serialisation {
msg: String,
},
}
#[derive(Debug, Clone, Display, Error)]
#[display("uom error: {} at {}:{}", kind, file, line)]
pub struct UomError {
pub kind: UomErrorKind,
pub line: u32,
pub file: &'static str,
}
impl UomError {
#[track_caller]
pub fn new(kind: UomErrorKind) -> Self {
let loc = std::panic::Location::caller();
Self {
kind,
line: loc.line(),
file: loc.file(),
}
}
}