Made MTTError a proper Error structure.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s

This commit is contained in:
2026-02-12 22:49:19 -05:00
parent 7ff9ca340f
commit a9b87200ef
12 changed files with 156 additions and 164 deletions

View File

@@ -1,5 +1,8 @@
use super::{Field, FieldType};
use crate::mtterror::MTTError;
use crate::{
mtterror::{ErrorID, MTTError},
name::NameType,
};
use chrono::{DateTime, Utc};
use std::time::Duration;
use uuid::Uuid;
@@ -349,7 +352,8 @@ impl Calculation {
if base == ftype {
self.values.push(holder);
} else {
return Err(MTTError::DocumentFieldWrongDataType(base, ftype));
let err = MTTError::new(NameType::None, ErrorID::FieldInvalidType);
return Err(err);
}
Ok(())
}
@@ -376,7 +380,8 @@ impl Calculation {
if base == ftype {
Ok(())
} else {
Err(MTTError::DocumentFieldWrongDataType(base, ftype))
let err = MTTError::new(NameType::None, ErrorID::FieldInvalidType);
return Err(err);
}
}
@@ -446,13 +451,13 @@ mod calculations {
calc.add_value(Uuid::nil()).unwrap();
match calc.add_value("other") {
Ok(_) => unreachable!("should have errored with wrong type"),
Err(err) => match err {
MTTError::DocumentFieldWrongDataType(expected, got) => {
assert_eq!(expected, FieldType::Uuid);
assert_eq!(got, FieldType::StaticString);
Err(err) => {
let err_id = err.error_id();
match err_id {
ErrorID::FieldInvalidType => {}
_ => unreachable!("got {:?}, expected wrong field type", err_id),
}
_ => unreachable!("got {:?}, expected wrong field type", err),
},
}
}
}
@@ -600,11 +605,8 @@ mod calculations {
calc.add_value(Uuid::nil()).unwrap();
match calc.add_value("mismatch") {
Ok(_) => unreachable!("should have returned an error"),
Err(err) => match err {
MTTError::DocumentFieldWrongDataType(expected, got) => {
assert_eq!(got, FieldType::StaticString);
assert_eq!(expected, FieldType::Uuid);
}
Err(err) => match err.error_id() {
ErrorID::FieldInvalidType => {}
_ => unreachable!("got {:?}, expected wrong field type", err),
},
}