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

@@ -5,7 +5,7 @@ use crate::{
field::Field,
},
message::wrapper::{InternalRecord, InternalRecords, Message, Oid, Records, Reply, Update},
mtterror::MTTError,
mtterror::{ErrorID, MTTError},
name::NameType,
queue::{
data_director::{Include, Path, RegMsg, Register, RouteID},
@@ -156,8 +156,8 @@ mod createdocs {
let result = rx.recv_timeout(TIMEOUT).unwrap();
assert_eq!(result.get_message_id(), msg2.get_message_id());
match result.get_action() {
MsgAction::Error(err) => match err {
MTTError::NameDuplicate(data) => assert_eq!(data, &name),
MsgAction::Error(err) => match err.error_id() {
ErrorID::NameAlreadyExists => {}
_ => unreachable!("got {:?}: should have been a duplicate name", err),
},
_ => unreachable!("got {:?}: should have been a reply.", result.get_action()),
@@ -222,7 +222,8 @@ impl Index {
}
};
if self.unique && oids.len() > 0 {
return Err(MTTError::FieldDuplicate);
let err = MTTError::new(NameType::None, ErrorID::IndexEntryAlreadyExists);
return Err(err);
} else {
oids.insert(oid);
}
@@ -238,7 +239,10 @@ impl Index {
output = output.union(&value).cloned().collect();
}
}
_ => return Err(MTTError::FieldInvalidType),
_ => {
let err = MTTError::new(NameType::None, ErrorID::FieldInvalidType);
return Err(err);
}
}
}
Ok(output)
@@ -259,7 +263,10 @@ impl Index {
fn validate(&self, field: &Field) -> Result<(), MTTError> {
if self.unique {
match self.data.get(field) {
Some(_) => return Err(MTTError::FieldDuplicate),
Some(_) => {
let err = MTTError::new(NameType::None, ErrorID::IndexEntryAlreadyExists);
return Err(err);
}
None => {}
}
}
@@ -416,10 +423,13 @@ mod indexes {
index.add(field.clone(), oids[0].clone()).unwrap();
match index.add(field.clone(), oids[0].clone()) {
Ok(_) => unreachable!("should have been an error"),
Err(err) => match err {
MTTError::FieldDuplicate => {}
_ => unreachable!("got {:?}: should have been duplicate field", err),
},
Err(err) => {
let err_id = err.error_id();
match err_id {
ErrorID::IndexEntryAlreadyExists => {}
_ => unreachable!("got {:?}: should have been duplicate field", err),
}
}
}
}
@@ -443,8 +453,8 @@ mod indexes {
index.add(field.clone(), oid).unwrap();
match index.validate(&field) {
Ok(_) => unreachable!("should have gotten a duplication error"),
Err(err) => match err {
MTTError::FieldDuplicate => {}
Err(err) => match err.error_id() {
ErrorID::IndexEntryAlreadyExists => {}
_ => unreachable!("got {:?}: should have been duplicate field", err),
},
}
@@ -1318,8 +1328,8 @@ mod document_files {
));
let result = test_doc.get_receiver().recv_timeout(TIMEOUT).unwrap();
match result.get_action() {
MsgAction::Error(err) => match err {
MTTError::NameNotFound(data) => assert_eq!(data, &name),
MsgAction::Error(err) => match err.error_id() {
ErrorID::NameNotFound => {}
_ => unreachable!("got {:?}: should have been document field not found.", err),
},
_ => unreachable!("got {:?}: should have been an error", result.get_action()),
@@ -1339,11 +1349,8 @@ mod document_files {
));
let result = test_doc.get_receiver().recv_timeout(TIMEOUT).unwrap();
match result.get_action() {
MsgAction::Error(err) => match err {
MTTError::DocumentFieldWrongDataType(expected, got) => {
assert_eq!(got, &FieldType::StaticString);
assert_eq!(expected, &FieldType::Uuid);
}
MsgAction::Error(err) => match err.error_id() {
ErrorID::FieldInvalidType => {}
_ => unreachable!(
"got {:?}: should have been document field data mismatch.",
err
@@ -1366,8 +1373,8 @@ mod document_files {
));
let result = test_doc.get_receiver().recv_timeout(TIMEOUT).unwrap();
match result.get_action() {
MsgAction::Error(err) => match err {
MTTError::InvalidNone => {}
MsgAction::Error(err) => match err.error_id() {
ErrorID::FieldInvalidNone => {}
_ => unreachable!("got {:?}: should have been document field missing", err),
},
_ => unreachable!("got {:?}: should have been an error", result.get_action()),
@@ -1646,8 +1653,8 @@ mod document_files {
let result = rx.recv_timeout(TIMEOUT).unwrap();
let action = result.get_action();
match action {
MsgAction::Error(data) => match data {
MTTError::NameNotFound(output) => assert_eq!(output, &field_name),
MsgAction::Error(data) => match data.error_id() {
ErrorID::NameNotFound => {}
_ => unreachable!("got {:?}: should been field not found", data),
},
_ => unreachable!("got {:?}: should have been a error", action),
@@ -1670,8 +1677,8 @@ mod document_files {
let result = doc.get_receiver().recv_timeout(TIMEOUT).unwrap();
let action = result.get_action();
match action {
MsgAction::Error(data) => match data {
MTTError::FieldInvalidType => {}
MsgAction::Error(data) => match data.error_id() {
ErrorID::FieldInvalidType => {}
_ => unreachable!("got {:?}: should been invalid field type", data),
},
_ => unreachable!("got {:?}: should have been a error", action),
@@ -1958,8 +1965,8 @@ mod document_files {
let result = doc.get_receiver().recv_timeout(TIMEOUT).unwrap();
let action = result.get_action();
match action {
MsgAction::Error(err) => match err {
MTTError::NameNotFound(data) => assert_eq!(data, &bad_name),
MsgAction::Error(err) => match err.error_id() {
ErrorID::NameNotFound => {}
_ => unreachable!("got {:?}: should have gotten an missing field", err),
},
_ => unreachable!("got {:?}: should have gotten an error", action),
@@ -1989,11 +1996,8 @@ mod document_files {
let result = doc.get_receiver().recv_timeout(TIMEOUT).unwrap();
let action = result.get_action();
match action {
MsgAction::Error(err) => match err {
MTTError::DocumentFieldWrongDataType(expected, got) => {
assert_eq!(expected, &FieldType::StaticString);
assert_eq!(got, &FieldType::Uuid);
}
MsgAction::Error(err) => match err.error_id() {
ErrorID::FieldInvalidType => {}
_ => unreachable!("got {:?}: should have gotten incorrect file type", err),
},
_ => unreachable!("got {:?}: should have gotten an error", action),
@@ -2043,8 +2047,8 @@ mod document_files {
let result = test_doc.get_receiver().recv_timeout(TIMEOUT).unwrap();
let action = result.get_action();
match action {
MsgAction::Error(err) => match err {
MTTError::FieldDuplicate => {}
MsgAction::Error(err) => match err.error_id() {
ErrorID::IndexEntryAlreadyExists => {}
_ => unreachable!("got {:?}: should have gotten incorrect file type", err),
},
_ => unreachable!("got {:?}: should have gotten an error", action),
@@ -2130,8 +2134,8 @@ mod document_files {
let result = doc.get_receiver().recv_timeout(TIMEOUT).unwrap();
let action = result.get_action();
match action {
MsgAction::Error(err) => match err {
MTTError::FieldDuplicate => {}
MsgAction::Error(err) => match err.error_id() {
ErrorID::IndexEntryAlreadyExists => {}
_ => unreachable!("got {:?}: should have gotten an missing field", err),
},
_ => unreachable!("got {:?}: should have gotten an error", action),
@@ -2171,8 +2175,8 @@ mod document_files {
let result = doc.get_receiver().recv_timeout(TIMEOUT).unwrap();
let action = result.get_action();
match action {
MsgAction::Error(err) => match err {
MTTError::FieldDuplicate => {}
MsgAction::Error(err) => match err.error_id() {
ErrorID::IndexEntryAlreadyExists => {}
_ => unreachable!("got {:?}: should have gotten field duplicate", err),
},
_ => unreachable!("got {:?}: should have gotten an error", action),
@@ -2282,8 +2286,8 @@ mod document_files {
let result = doc.get_receiver().recv_timeout(TIMEOUT).unwrap();
let action = result.get_action();
match action {
MsgAction::Error(err) => match err {
MTTError::NameNotFound(data) => assert_eq!(data, &field_name),
MsgAction::Error(err) => match err.error_id() {
ErrorID::NameNotFound => {}
_ => unreachable!("got {:?}: should have gotten an missing field", err),
},
_ => unreachable!("got {:?}: should have gotten an error", action),