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),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ impl From<UserAction> for MsgAction {
|
||||
#[cfg(test)]
|
||||
mod msgactions {
|
||||
use super::*;
|
||||
use crate::name::Name;
|
||||
use crate::{mtterror::ErrorID, name::Name};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[test]
|
||||
@@ -120,23 +120,20 @@ mod msgactions {
|
||||
|
||||
#[test]
|
||||
fn turn_error_into_action() {
|
||||
let data = "data".to_string();
|
||||
let value = MTTError::DocumentAlreadyExists(data.clone());
|
||||
let result: MsgAction = value.into();
|
||||
let doc_name = Name::english(Uuid::new_v4().to_string().as_str());
|
||||
let expected_name: NameType = doc_name.clone().into();
|
||||
let error = ErrorID::DocumentNameAlreadyExists;
|
||||
let err = MTTError::new(doc_name.clone(), error.clone());
|
||||
let result: MsgAction = err.into();
|
||||
match result {
|
||||
MsgAction::Error(result) => match result {
|
||||
MTTError::DocumentAlreadyExists(output) => assert_eq!(output, data),
|
||||
_ => unreachable!("Got {:?}: dhould have been create", result),
|
||||
},
|
||||
_ => unreachable!("Got {:?}: dhould have been create", result),
|
||||
}
|
||||
let value = MTTError::DocumentNotFound(data.clone());
|
||||
let result: MsgAction = value.into();
|
||||
match result {
|
||||
MsgAction::Error(result) => match result {
|
||||
MTTError::DocumentNotFound(output) => assert_eq!(output, data),
|
||||
_ => unreachable!("Got {:?}: dhould have been create", result),
|
||||
},
|
||||
MsgAction::Error(err) => {
|
||||
assert_eq!(err.doc_name(), &expected_name);
|
||||
let err_id = err.error_id();
|
||||
match err_id {
|
||||
ErrorID::DocumentNameAlreadyExists => {}
|
||||
_ => unreachable!("got {:?}, expected document name exists", err_id),
|
||||
}
|
||||
}
|
||||
_ => unreachable!("Got {:?}: dhould have been create", result),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user