Added errprs.
Some checks failed
MoreThanText/morethantext/pipeline/head There was a failure building this commit
Some checks failed
MoreThanText/morethantext/pipeline/head There was a failure building this commit
This commit is contained in:
parent
2bf495b127
commit
508b8269d0
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,4 +1,4 @@
|
|||||||
/target
|
/target
|
||||||
*.pyc
|
*.pyc
|
||||||
*.swp
|
*.swp
|
||||||
|
*.swo
|
||||||
|
@ -33,7 +33,7 @@ impl Table {
|
|||||||
None => {
|
None => {
|
||||||
self.fields.insert(name.to_string(), FieldDef::new());
|
self.fields.insert(name.to_string(), FieldDef::new());
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -61,7 +61,7 @@ mod table {
|
|||||||
tbl.add_field("one", "id");
|
tbl.add_field("one", "id");
|
||||||
match tbl.add_field("one", "id") {
|
match tbl.add_field("one", "id") {
|
||||||
Ok(_) => unreachable!(" Should not duplicates."),
|
Ok(_) => unreachable!(" Should not duplicates."),
|
||||||
Err(_) => {},
|
Err(_) => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
51
src/error.rs
Normal file
51
src/error.rs
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
use std::{error::Error, fmt};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
enum ErrorType {
|
||||||
|
TableAddFieldDuplicate(String),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for ErrorType {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
ErrorType::TableAddFieldDuplicate(data) => write!(f, "field '{}' already exists", data),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct MTTError {
|
||||||
|
err: ErrorType,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MTTError {
|
||||||
|
fn new(err: ErrorType) -> Self {
|
||||||
|
Self {
|
||||||
|
err: err,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Error for MTTError {}
|
||||||
|
|
||||||
|
impl fmt::Display for MTTError {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
write!(f, "{}", self.err.to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod errors {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn get_error() {
|
||||||
|
let err = MTTError::new(ErrorType::TableAddFieldDuplicate("tester".to_string()));
|
||||||
|
assert_eq!(err.to_string(), "field 'tester' already exists");
|
||||||
|
assert!(err.source().is_none());
|
||||||
|
let err = MTTError::new(ErrorType::TableAddFieldDuplicate("other".to_string()));
|
||||||
|
assert_eq!(err.to_string(), "field 'other' already exists");
|
||||||
|
assert!(err.source().is_none());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,6 @@
|
|||||||
mod client;
|
mod client;
|
||||||
mod data;
|
mod data;
|
||||||
|
mod error;
|
||||||
mod message;
|
mod message;
|
||||||
mod router;
|
mod router;
|
||||||
mod session;
|
mod session;
|
||||||
|
Loading…
Reference in New Issue
Block a user