all MizeError's are now constructed with the new() function instead of with directly with {}
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -1806,6 +1806,7 @@ dependencies = [
|
|||||||
"futures-util",
|
"futures-util",
|
||||||
"itertools",
|
"itertools",
|
||||||
"json",
|
"json",
|
||||||
|
"lazy_static",
|
||||||
"surrealdb",
|
"surrealdb",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-stream",
|
"tokio-stream",
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ axum-macros = "0.3.0"
|
|||||||
futures-util = "0.3.24"
|
futures-util = "0.3.24"
|
||||||
itertools = "0.10.5"
|
itertools = "0.10.5"
|
||||||
json = "0.12.4"
|
json = "0.12.4"
|
||||||
|
lazy_static = "1.4.0"
|
||||||
surrealdb = "1.0.0-beta.7"
|
surrealdb = "1.0.0-beta.7"
|
||||||
tokio = {version = "1.21.0", features = ["full"]}
|
tokio = {version = "1.21.0", features = ["full"]}
|
||||||
tokio-stream = "0.1.9"
|
tokio-stream = "0.1.9"
|
||||||
|
|||||||
@@ -1,68 +0,0 @@
|
|||||||
Not sure yet:
|
|
||||||
code: 11
|
|
||||||
category: "don't know yet"
|
|
||||||
|
|
||||||
Can't delete item 0:
|
|
||||||
code: 100
|
|
||||||
category: "don't know yet"
|
|
||||||
message: "You can't delete item number 0. This item contains mandatory Config for the Server."
|
|
||||||
|
|
||||||
Error with Surrealdb:
|
|
||||||
code: 128
|
|
||||||
category: "data_storage"
|
|
||||||
|
|
||||||
num_of_items missing in item0:
|
|
||||||
code: 101
|
|
||||||
category: "key_missing::item0::num_of_items"
|
|
||||||
|
|
||||||
next_free_id missing in item0:
|
|
||||||
code: 102
|
|
||||||
category: "key_missing::item0::next_free_id"
|
|
||||||
|
|
||||||
_commit missing in item0:
|
|
||||||
code: 103
|
|
||||||
category: "key_missing::item0::_commit"
|
|
||||||
|
|
||||||
_commit missing:
|
|
||||||
code: 103
|
|
||||||
category: "key_missing::_commit"
|
|
||||||
|
|
||||||
could not read index of item:
|
|
||||||
code: 104
|
|
||||||
category: "data_storage::index_not_found"
|
|
||||||
|
|
||||||
_commit not 8 bytes long:
|
|
||||||
code: 105
|
|
||||||
category: "don't know yet"
|
|
||||||
|
|
||||||
error while parsing int:
|
|
||||||
code: 106
|
|
||||||
category: "parse_error"
|
|
||||||
|
|
||||||
error with message sent to the server:
|
|
||||||
code: 107
|
|
||||||
category: "faulty_message"
|
|
||||||
|
|
||||||
missing metadata:
|
|
||||||
code: 108
|
|
||||||
category: "faulty_message"
|
|
||||||
|
|
||||||
something that should be utf8 valid was not:
|
|
||||||
code: 109
|
|
||||||
category: "faulty_message"
|
|
||||||
|
|
||||||
ParseIntError:
|
|
||||||
code: 110
|
|
||||||
category: "faulty_message"
|
|
||||||
|
|
||||||
_commit can't be updated:
|
|
||||||
code: 111
|
|
||||||
category: "faulty_update"
|
|
||||||
|
|
||||||
no / on the end of id:
|
|
||||||
code: 112
|
|
||||||
category: "faulty_message"
|
|
||||||
|
|
||||||
module header not a String:
|
|
||||||
code: 113
|
|
||||||
category: "don't know yet"
|
|
||||||
86
errors.toml
Normal file
86
errors.toml
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
|
||||||
|
[[error]]
|
||||||
|
code = 11
|
||||||
|
category = "don't know yet"
|
||||||
|
message = "Something went wrong. Someone was too lazy to define an exact error for that."
|
||||||
|
|
||||||
|
[[error]]
|
||||||
|
code = 100
|
||||||
|
category = "don't know yet"
|
||||||
|
message = "You can't delete item number 0. This item contains mandatory Config for the Server."
|
||||||
|
|
||||||
|
[[error]]
|
||||||
|
category = "data_storage"
|
||||||
|
code = 128
|
||||||
|
message = "Something went wrong in the data storage."
|
||||||
|
|
||||||
|
[[error]]
|
||||||
|
code = 129
|
||||||
|
category = "data_storage:surrealdb_error"
|
||||||
|
message = "Something went wrong internally with the data-storage (surrealdb): {}"
|
||||||
|
|
||||||
|
[[error]]
|
||||||
|
code = 101
|
||||||
|
category = "key_missing::item0::num_of_items"
|
||||||
|
messate = "num_of_items missing in item0"
|
||||||
|
|
||||||
|
[[error]]
|
||||||
|
code = 102
|
||||||
|
category = "key_missing::item0::next_free_id"
|
||||||
|
message = "next_free_id missing in item0"
|
||||||
|
|
||||||
|
[[error]]
|
||||||
|
_commit missing in item0:
|
||||||
|
code = 103
|
||||||
|
category = "key_missing::item0::_commit"
|
||||||
|
|
||||||
|
[[error]]
|
||||||
|
_commit missing:
|
||||||
|
code = 103
|
||||||
|
category = "key_missing::_commit"
|
||||||
|
|
||||||
|
[[error]]
|
||||||
|
code = 104
|
||||||
|
category = "data_storage::index_not_found"
|
||||||
|
message = "could not read index of item"
|
||||||
|
|
||||||
|
[[error]]
|
||||||
|
code = 105
|
||||||
|
category = "don't know yet"
|
||||||
|
message = "_commit not 8 bytes long"
|
||||||
|
|
||||||
|
[[error]]
|
||||||
|
code = 106
|
||||||
|
category = "parse_error"
|
||||||
|
message = "error while parsing to an int"
|
||||||
|
|
||||||
|
[[error]]
|
||||||
|
code = 107
|
||||||
|
category = "faulty_message"
|
||||||
|
message = "some error with message sent to the server"
|
||||||
|
|
||||||
|
[[error]]
|
||||||
|
code = 108
|
||||||
|
category = "faulty_message"
|
||||||
|
message = "There was not metadata in a message, that should have some."
|
||||||
|
|
||||||
|
[[error]]
|
||||||
|
code = 109
|
||||||
|
category = "faulty_message"
|
||||||
|
message = "something that should be utf8 valid was not"
|
||||||
|
|
||||||
|
[[error]]
|
||||||
|
code = 111
|
||||||
|
category = "faulty_update"
|
||||||
|
message = "mize-commit can't be updated manually"
|
||||||
|
|
||||||
|
[[error]]
|
||||||
|
code = 113
|
||||||
|
category = "don't know yet"
|
||||||
|
message = "module header not a String"
|
||||||
|
|
||||||
|
[[error]]
|
||||||
|
code 114
|
||||||
|
category = "error with error system"
|
||||||
|
message = "the error with code {} was not found in the errors.toml file"
|
||||||
|
|
||||||
66
src/error.rs
66
src/error.rs
@@ -1,24 +1,63 @@
|
|||||||
|
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::string::FromUtf8Error;
|
use std::string::FromUtf8Error;
|
||||||
|
|
||||||
|
lazy_static::lazy_static! {
|
||||||
|
static ref ERRORS: HashMap<u32, MizeError> = parse_errors();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_errors() -> HashMap<u32, MizeError>{
|
||||||
|
let toml_string = include_str!("../errors.toml");
|
||||||
|
}
|
||||||
|
|
||||||
use json;
|
use json;
|
||||||
|
use toml;
|
||||||
use crate::server::proto;
|
use crate::server::proto;
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct MizeError {
|
pub struct MizeError {
|
||||||
pub kind: String,
|
pub category: String,
|
||||||
pub code: u32,
|
pub code: u32,
|
||||||
pub message: String,
|
pub message: String,
|
||||||
|
pub extra_msg: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MizeError {
|
impl MizeError {
|
||||||
|
pub fn new(code: u32) -> MizeError {
|
||||||
|
//let error = ERRORS.
|
||||||
|
|
||||||
|
MizeError {
|
||||||
|
category: "error with error system".to_string(),
|
||||||
|
code: 114,
|
||||||
|
message: "The error with code {} was not found in the errors.toml file".to_string(),
|
||||||
|
extra_msg: None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// pub fn format(&self, values: [str]){
|
||||||
|
// }
|
||||||
|
|
||||||
|
pub fn extra_msg(mut self, msg: &str) -> MizeError{
|
||||||
|
self.extra_msg = Some(msg.to_string());
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn to_json(self: MizeError) -> json::JsonValue{
|
pub fn to_json(self: MizeError) -> json::JsonValue{
|
||||||
let data = json::object!{
|
if let Some(extra_msg) = self.extra_msg {
|
||||||
kind: self.kind,
|
json::object!{
|
||||||
|
category: self.category,
|
||||||
code: self.code,
|
code: self.code,
|
||||||
message: self.message,
|
message: self.message,
|
||||||
};
|
extra_msg: extra_msg,
|
||||||
return data;
|
}
|
||||||
|
} else {
|
||||||
|
json::object!{
|
||||||
|
category: self.category,
|
||||||
|
code: self.code,
|
||||||
|
message: self.message,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_message(self: MizeError, origin: proto::Origin) -> proto::Message {
|
pub fn to_message(self: MizeError, origin: proto::Origin) -> proto::Message {
|
||||||
@@ -27,28 +66,17 @@ impl MizeError {
|
|||||||
msg.extend(json::stringify(data).into_bytes());
|
msg.extend(json::stringify(data).into_bytes());
|
||||||
return proto::Message::from_bytes(msg, origin);
|
return proto::Message::from_bytes(msg, origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<FromUtf8Error> for MizeError {
|
impl From<FromUtf8Error> for MizeError {
|
||||||
fn from(utf_err: FromUtf8Error) -> MizeError{
|
fn from(utf_err: FromUtf8Error) -> MizeError{
|
||||||
let err = MizeError {
|
MizeError::new(109).extra_msg("std::string::FromUtf8Error while parsing something from the message")
|
||||||
code: 109,
|
|
||||||
kind: "faulty_message".to_string(),
|
|
||||||
message: "std::string::FromUtf8Error while parsing something from the message".to_string(),
|
|
||||||
};
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<surrealdb::Error> for MizeError {
|
impl From<surrealdb::Error> for MizeError {
|
||||||
fn from(sur_err: surrealdb::Error) -> MizeError{
|
fn from(sur_err: surrealdb::Error) -> MizeError{
|
||||||
let cat = format!("data-storage:surrealdb:{:?}", sur_err);
|
MizeError::new(129)
|
||||||
let msg = format!("Something went wrong internally with the data-storage:surrealdb: {}", sur_err);
|
|
||||||
let err = MizeError {
|
|
||||||
code: 128,
|
|
||||||
kind: cat,
|
|
||||||
message: msg,
|
|
||||||
};
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use futures_util::{FutureExt, StreamExt, SinkExt};
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::boxed::Box;
|
use std::boxed::Box;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
use crate::error;
|
||||||
use crate::error::MizeError;
|
use crate::error::MizeError;
|
||||||
|
|
||||||
use tokio::sync::mpsc::{Sender, channel, Receiver};
|
use tokio::sync::mpsc::{Sender, channel, Receiver};
|
||||||
@@ -133,6 +134,10 @@ impl Mutexes {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test(){
|
||||||
|
println!("test func");
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
pub async fn run_server(args: Vec<String>) {
|
pub async fn run_server(args: Vec<String>) {
|
||||||
/*
|
/*
|
||||||
@@ -152,6 +157,13 @@ pub async fn run_server(args: Vec<String>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//load the errors.toml file and init the error system
|
||||||
|
//let error_toml_file = include_str!("../errors.toml");
|
||||||
|
//println!("ERRORS: {:?}", crate::error::ERRORS);
|
||||||
|
error::init();
|
||||||
|
println!("hello in run_server");
|
||||||
|
test();
|
||||||
|
|
||||||
//create the itemstore
|
//create the itemstore
|
||||||
let itemstore = crate::server::itemstore::Itemstore::new(mize_folder.clone() + "/db").await.expect("error creating itemstore");
|
let itemstore = crate::server::itemstore::Itemstore::new(mize_folder.clone() + "/db").await.expect("error creating itemstore");
|
||||||
|
|
||||||
@@ -335,11 +347,9 @@ async fn handle_websocket_connection(
|
|||||||
if let Ok(name) = mod_header_val.to_str() {
|
if let Ok(name) = mod_header_val.to_str() {
|
||||||
module.name = name.to_string();
|
module.name = name.to_string();
|
||||||
} else {
|
} else {
|
||||||
let err = MizeError{
|
let err = MizeError::new(113)
|
||||||
code: 113,
|
.extra_msg("The mize-module Header could not be decoded into a String.");
|
||||||
kind: "don't know yet".to_string(),
|
|
||||||
message: "The mize-module Header could not be decoded into a String.".to_string(),
|
|
||||||
};
|
|
||||||
msg_tx.send(err.to_message(proto::Origin::Module(module.clone()))).await;
|
msg_tx.send(err.to_message(proto::Origin::Module(module.clone()))).await;
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
@@ -389,11 +399,9 @@ async fn handle_websocket_connection(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let err = MizeError{
|
let err = MizeError::new(11)
|
||||||
code: 11,
|
.extra_msg("the message type was not Binary");
|
||||||
kind: "don't know yet".to_string(),
|
|
||||||
message: "the message type was not Binary".to_string(),
|
|
||||||
};
|
|
||||||
msg_tx.send(err.to_message(origin.clone())).await;
|
msg_tx.send(err.to_message(origin.clone())).await;
|
||||||
vec![0]
|
vec![0]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -94,11 +94,8 @@ impl Itemstore {
|
|||||||
let mut old_keys = match tr.get(format!("{}", update.id).into_bytes()).await? {
|
let mut old_keys = match tr.get(format!("{}", update.id).into_bytes()).await? {
|
||||||
Some(keys) => decode(keys),
|
Some(keys) => decode(keys),
|
||||||
None => {
|
None => {
|
||||||
return Err(MizeError{
|
return Err(MizeError::new(104)
|
||||||
code: 104,
|
.extra_msg("Internal Datastorage Error: the Index of the Item was not found"));
|
||||||
kind: "data_storage::index_not_found".to_string(),
|
|
||||||
message: "Internal Datastorage Error: the Index of the Item was not found".to_string(),
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -146,12 +143,8 @@ impl Itemstore {
|
|||||||
let id_u64: u64 = match id_str.parse() {
|
let id_u64: u64 = match id_str.parse() {
|
||||||
Ok(id) => id,
|
Ok(id) => id,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
return Err(MizeError {
|
return Err(MizeError::new(110)
|
||||||
code: 110,
|
.extra_msg("std::num::ParseIntError while parsing id \"{}\" into an Integer"));
|
||||||
kind: "faulty_message".to_string(),
|
|
||||||
message: format!("std::num::ParseIntError while parsing id \"{}\" into an Integer", id_str),
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let mut tr = self.db.transaction(true, true).await?;
|
let mut tr = self.db.transaction(true, true).await?;
|
||||||
@@ -162,11 +155,9 @@ impl Itemstore {
|
|||||||
tr.del(key).await?;
|
tr.del(key).await?;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return Err(MizeError{
|
return Err(MizeError::new(104)
|
||||||
code: 104,
|
.extra_msg("Internal Datastorage Error: the Index of the Item was not found, \
|
||||||
kind: "data_storage::index_not_found".to_string(),
|
This means most likely that this item does not exist."));
|
||||||
message: "Internal Datastorage Error: the Index of the Item was not found, This means most likely that this item does not exist.".to_string(),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tr.del(id_str.into_bytes()).await?;
|
tr.del(id_str.into_bytes()).await?;
|
||||||
@@ -197,11 +188,8 @@ impl Itemstore {
|
|||||||
};
|
};
|
||||||
return Ok(item);
|
return Ok(item);
|
||||||
} else {
|
} else {
|
||||||
return Err(MizeError{
|
return Err(MizeError::new(104)
|
||||||
code: 104,
|
.extra_msg("Internal Datastorage Error: the Index of the Item was not found"));
|
||||||
kind: "data_storage::index_not_found".to_string(),
|
|
||||||
message: "Internal Datastorage Error: the Index of the Item was not found".to_string(),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return Ok(item);
|
return Ok(item);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,11 +126,7 @@ pub enum DeltaCmd {
|
|||||||
|
|
||||||
impl Delta {
|
impl Delta {
|
||||||
pub fn from_bytes(bytes: Vec<u8>) -> Result<Delta, MizeError> {
|
pub fn from_bytes(bytes: Vec<u8>) -> Result<Delta, MizeError> {
|
||||||
let out_of_bytes = Err(MizeError{
|
let out_of_bytes = Err(MizeError::new(107).extra_msg("There were not eneough Bytes in the message to complete a Delta."));
|
||||||
code: 107,
|
|
||||||
kind: "faulty_message".to_string(),
|
|
||||||
message: "There were not eneough Bytes in the message to complete a Delta.".to_string()
|
|
||||||
});
|
|
||||||
let mut bytes = bytes.iter();
|
let mut bytes = bytes.iter();
|
||||||
let mut delta = Delta{raw: Vec::new()};
|
let mut delta = Delta{raw: Vec::new()};
|
||||||
|
|
||||||
@@ -183,11 +179,9 @@ impl Delta {
|
|||||||
delta.raw.push(DeltaCmd::Delete(start, stop));
|
delta.raw.push(DeltaCmd::Delete(start, stop));
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
return Err(MizeError{
|
return Err(MizeError::new(107)
|
||||||
code: 107,
|
.extra_msg(&format!("The update message included a DeltaCmd of {}.\
|
||||||
kind: "faulty_message".to_string(),
|
Only 0,1,2 (for: replace, insert, delete) are allowed.", cmd)));
|
||||||
message: format!("The update message included a DeltaCmd of {}, only 0,1,2 (for: replace, insert, delete) are allowed.",cmd)
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -203,11 +197,9 @@ impl Update {
|
|||||||
let id_u64 = match id.parse::<u64>(){
|
let id_u64 = match id.parse::<u64>(){
|
||||||
Ok(id) => id,
|
Ok(id) => id,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
return Err(MizeError{
|
return Err(MizeError::new(11)
|
||||||
code: 11,
|
.extra_msg("Error while parsing id to u64 (std::num::ParseIntError) in order to get it from the itemstore.\
|
||||||
kind: "don't know yet".to_string(),
|
(get or get_sub message)"));
|
||||||
message: "Error while parsing id to u64 (std::num::ParseIntError) in order to get it from the itemstore. (get or get_sub message)".to_string(),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -393,18 +385,10 @@ impl Message {
|
|||||||
|
|
||||||
pub fn get_metadata(&mut self) -> Result<HashMap<String, String>, MizeError> {
|
pub fn get_metadata(&mut self) -> Result<HashMap<String, String>, MizeError> {
|
||||||
if !self.has_meta {
|
if !self.has_meta {
|
||||||
return Err(MizeError {
|
return Err(MizeError::new(108).extra_msg("The message should have medatata, but it hasn't. (cmd <= 128)"))
|
||||||
code: 108,
|
|
||||||
kind: "faulty_message".to_string(),
|
|
||||||
message: "The message should have medatata, but it hasn't. (cmd <= 128)".to_string(),
|
|
||||||
})
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let meta_err = MizeError {
|
let meta_err = MizeError::new(107).extra_msg("Error while parsing the metadata of a message.");
|
||||||
code: 107,
|
|
||||||
kind: "faulty_message".to_string(),
|
|
||||||
message: "Error while parsing the metadata of a message.".to_string(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut meta_vec:Vec<u8> = Vec::new();
|
let mut meta_vec:Vec<u8> = Vec::new();
|
||||||
let mut msg_iter = self.raw[self.index..].iter();
|
let mut msg_iter = self.raw[self.index..].iter();
|
||||||
@@ -433,11 +417,7 @@ impl Message {
|
|||||||
meta_vec.push(*ch);
|
meta_vec.push(*ch);
|
||||||
};
|
};
|
||||||
|
|
||||||
return Err(MizeError {
|
return Err(MizeError::new(107).extra_msg("Error while parsing the metadata of a message."))
|
||||||
code: 107,
|
|
||||||
kind: "faulty_message".to_string(),
|
|
||||||
message: "Error while parsing the metadata of a message.".to_string(),
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -463,11 +443,7 @@ impl Message {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Err(MizeError {
|
return Err(MizeError::new(112).extra_msg("There is no / to indicate where the id ends"));
|
||||||
code: 112,
|
|
||||||
kind: "faulty_message".to_string(),
|
|
||||||
message: "There is no / to indicate where the id ends".to_string(),
|
|
||||||
});
|
|
||||||
|
|
||||||
// let len = self.raw.len();
|
// let len = self.raw.len();
|
||||||
// while self.index < 10000 {
|
// while self.index < 10000 {
|
||||||
@@ -548,11 +524,8 @@ pub async fn handle_mize_message(
|
|||||||
|
|
||||||
//forward to module in case the item is from a Module
|
//forward to module in case the item is from a Module
|
||||||
//append medatata
|
//append medatata
|
||||||
let first_char = id.chars().nth(0).ok_or(MizeError{
|
let first_char = id.chars().nth(0)
|
||||||
code: 11,
|
.ok_or(MizeError::new(11).extra_msg("Somehow the id is empty. while handling a get or get_sub message."))?;
|
||||||
kind: "don't know yet".to_string(),
|
|
||||||
message: "Somehow the id is empty. while handling a get or get_sub message.".to_string(),
|
|
||||||
})?;
|
|
||||||
|
|
||||||
if (first_char == '!'){
|
if (first_char == '!'){
|
||||||
message.clone().forward_module(id.clone(), mutexes.clone()).await;
|
message.clone().forward_module(id.clone(), mutexes.clone()).await;
|
||||||
@@ -583,11 +556,9 @@ pub async fn handle_mize_message(
|
|||||||
let id_u64 = match id.parse::<u64>(){
|
let id_u64 = match id.parse::<u64>(){
|
||||||
Ok(id) => id,
|
Ok(id) => id,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
return Err(MizeError{
|
return Err(MizeError::new(11)
|
||||||
code: 11,
|
.extra_msg("Error while parsing id to u64 in order to get it from the itemstore.\
|
||||||
kind: "don't know yet".to_string(),
|
(get or get_sub message)"));
|
||||||
message: "Error while parsing id to u64 in order to get it from the itemstore. (get or get_sub message)".to_string(),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -620,18 +591,14 @@ pub async fn handle_mize_message(
|
|||||||
if (message.cmd == MSG_GIVE && matches!(&message.origin, Origin::Module(_))){
|
if (message.cmd == MSG_GIVE && matches!(&message.origin, Origin::Module(_))){
|
||||||
let meta = message.get_metadata()?;
|
let meta = message.get_metadata()?;
|
||||||
let id: String = message.get_id()?;
|
let id: String = message.get_id()?;
|
||||||
let client_id_str = meta.get("c").ok_or(MizeError{
|
let client_id_str = meta.get("c")
|
||||||
code: 11,
|
.ok_or(MizeError::new(11)
|
||||||
kind: "don't know yet".to_string(),
|
.extra_msg("there is no \"c\" key in the metadata of a message gotten from a module"))?;
|
||||||
message: "there is no \"c\" key in the metadata of a message gotten from a module".to_string(),
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let client_id: u64 = client_id_str.parse().map_err(|_| MizeError{
|
|
||||||
code: 11,
|
|
||||||
kind: "don't know yet".to_string(),
|
|
||||||
message: "Error (std::num::ParseIntError) while parsing the \"c\" key in the Message metadata from a give Message from a Module".to_string()
|
|
||||||
})?;
|
|
||||||
|
|
||||||
|
let client_id: u64 = client_id_str.parse()
|
||||||
|
.map_err(|_| MizeError::new(11)
|
||||||
|
.extra_msg("Error (std::num::ParseIntError) while parsing the \"c\" key \
|
||||||
|
in the Message metadata from a give Message from a Module"))?;
|
||||||
|
|
||||||
let clients = mutexes.clients.lock().await;
|
let clients = mutexes.clients.lock().await;
|
||||||
let modules = mutexes.modules.lock().await;
|
let modules = mutexes.modules.lock().await;
|
||||||
@@ -646,11 +613,7 @@ pub async fn handle_mize_message(
|
|||||||
} else if (client.len() == 1) {
|
} else if (client.len() == 1) {
|
||||||
Origin::Client(client[0].to_owned())
|
Origin::Client(client[0].to_owned())
|
||||||
} else {
|
} else {
|
||||||
return Err(MizeError{
|
return Err(MizeError::new(11))
|
||||||
code: 11,
|
|
||||||
kind: "don't know yet".to_string(),
|
|
||||||
message: "".to_string()
|
|
||||||
})
|
|
||||||
};
|
};
|
||||||
|
|
||||||
drop(clients);
|
drop(clients);
|
||||||
@@ -694,11 +657,9 @@ pub async fn handle_mize_message(
|
|||||||
if (message.cmd == MSG_UPDATE_REQUEST && (matches!(&message.origin, Origin::Module(_)) || matches!(&message.origin, Origin::Client(_)))){
|
if (message.cmd == MSG_UPDATE_REQUEST && (matches!(&message.origin, Origin::Module(_)) || matches!(&message.origin, Origin::Client(_)))){
|
||||||
|
|
||||||
let id: String = message.get_id()?;
|
let id: String = message.get_id()?;
|
||||||
let first_char = id.chars().nth(0).ok_or(MizeError{
|
let first_char = id.chars().nth(0)
|
||||||
code: 11,
|
.ok_or(MizeError::new(11)
|
||||||
kind: "don't know yet".to_string(),
|
.extra_msg("Somehow the id is empty. while handling a get or get_sub message."))?;
|
||||||
message: "Somehow the id is empty. while handling a get or get_sub message.".to_string(),
|
|
||||||
})?;
|
|
||||||
|
|
||||||
if (first_char == '!'){
|
if (first_char == '!'){
|
||||||
message.clone().forward_module(id, mutexes.clone()).await;
|
message.clone().forward_module(id, mutexes.clone()).await;
|
||||||
@@ -715,11 +676,7 @@ pub async fn handle_mize_message(
|
|||||||
if (message.cmd == MSG_DELETE && (matches!(&message.origin, Origin::Module(_)) || matches!(&message.origin, Origin::Client(_)))){
|
if (message.cmd == MSG_DELETE && (matches!(&message.origin, Origin::Module(_)) || matches!(&message.origin, Origin::Client(_)))){
|
||||||
let id: String = message.get_id()?;
|
let id: String = message.get_id()?;
|
||||||
if id == "0".to_string() {
|
if id == "0".to_string() {
|
||||||
let err = error::MizeError {
|
let err = MizeError::new(100);
|
||||||
kind: "don't know yet".to_string(),
|
|
||||||
code: 100,
|
|
||||||
message: "You can't delete item number 0. This item contains mandatory Config for the Server.".to_string(),
|
|
||||||
};
|
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
return Ok(());
|
return Ok(());
|
||||||
@@ -814,24 +771,20 @@ pub async fn handle_update(mut update: Update, mutexes: Mutexes, origin: Origin)
|
|||||||
let id_u64 = match update.id.clone().parse::<u64>(){
|
let id_u64 = match update.id.clone().parse::<u64>(){
|
||||||
Ok(id) => id,
|
Ok(id) => id,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
return Err(MizeError{
|
return Err(MizeError::new(11)
|
||||||
code: 11,
|
.extra_msg("Error while parsing id to u64 in order to get it from the itemstore.\
|
||||||
kind: "don't know yet".to_string(),
|
(get or get_sub message)"));
|
||||||
message: "Error while parsing id to u64 in order to get it from the itemstore. (get or get_sub message)".to_string(),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let item = itemstore.get(id_u64).await?;
|
let item = itemstore.get(id_u64).await?;
|
||||||
let commit_pos = item.iter().position(|field| field[0] == "_commit".to_string().into_bytes()).ok_or(MizeError{
|
let commit_pos = item.iter()
|
||||||
code: 103,
|
.position(|field| field[0] == "_commit".to_string().into_bytes())
|
||||||
kind: "key_missing::_commit".to_string(),
|
.ok_or(MizeError::new(103)
|
||||||
message: format!("Item {} has not _commit", id_u64),
|
.extra_msg(&format!("Item {} has not _commit", id_u64)))?;
|
||||||
})?;
|
|
||||||
let cur_commit = u64::from_be_bytes(item[commit_pos][1].clone().try_into().map_err(|_|MizeError{
|
let cur_commit = u64::from_be_bytes(item[commit_pos][1].clone().try_into()
|
||||||
code: 105,
|
.map_err(|_|MizeError::new(105))?
|
||||||
kind: "don't know yet".to_string(),
|
);
|
||||||
message: "_commit is not 8 bytes long".to_string(),
|
|
||||||
})?);
|
|
||||||
|
|
||||||
//because Update::change_whole_val trys to lock the itemstore as well
|
//because Update::change_whole_val trys to lock the itemstore as well
|
||||||
drop(itemstore);
|
drop(itemstore);
|
||||||
|
|||||||
Reference in New Issue
Block a user