Made MTTError a proper Error structure.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s
This commit is contained in:
@@ -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),
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user