Completed entry point.
Some checks failed
MoreThanText/morethantext/pipeline/head There was a failure building this commit

This commit is contained in:
2024-12-13 14:34:20 -05:00
parent 78741c4ff8
commit 3868ab44dd
3 changed files with 127 additions and 3 deletions

View File

@ -1,4 +1,4 @@
use crate::data::{database::DBError, id::IDError, table::TBLError};
use crate::data::{database::DBError, id::IDError, table::TBLError, UniError};
use std::{error::Error, fmt};
#[derive(Debug)]
@ -6,6 +6,7 @@ pub enum ErrorType {
DBErr(DBError),
IDErr(IDError),
TBLErr(TBLError),
UniErr(UniError),
}
impl From<DBError> for ErrorType {
@ -26,12 +27,19 @@ impl From<TBLError> for ErrorType {
}
}
impl From<UniError> for ErrorType {
fn from(value: UniError) -> Self {
ErrorType::UniErr(value)
}
}
impl fmt::Display for ErrorType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ErrorType::DBErr(data) => write!(f, "database: {}", data),
ErrorType::IDErr(data) => write!(f, "id: {}", data),
ErrorType::TBLErr(data) => write!(f, "table: {}", data),
ErrorType::UniErr(data) => write!(f, "global: {}", data),
}
}
}
@ -60,6 +68,13 @@ mod errortypes {
let result = ErrorType::from(err.clone());
assert_eq!(result.to_string(), format!("table: {}", err));
}
#[test]
fn universal_error() {
let err = UniError::DuplicateDB("bad".to_string());
let result = ErrorType::from(err.clone());
assert_eq!(result.to_string(), format!("global: {}", err));
}
}
#[derive(Debug)]
@ -109,6 +124,12 @@ impl From<TBLError> for MTTError {
}
}
impl From<UniError> for MTTError {
fn from(value: UniError) -> Self {
Self { err: value.into() }
}
}
#[cfg(test)]
mod errors {
use super::*;
@ -142,4 +163,11 @@ mod errors {
let err = MTTError::from(error.clone());
assert_eq!(err.to_string(), ErrorType::TBLErr(error).to_string());
}
#[test]
fn from_global_error() {
let error = UniError::DuplicateDB(rand_str());
let err = MTTError::from(error.clone());
assert_eq!(err.to_string(), ErrorType::UniErr(error).to_string());
}
}