Revert "Add error module for error handling"
This reverts commit e9b122f612
.
This commit is contained in:
parent
f1a67dba10
commit
3df9343412
3 changed files with 29 additions and 51 deletions
35
src/error.rs
35
src/error.rs
|
@ -1,35 +0,0 @@
|
||||||
use runtime::Runtime;
|
|
||||||
|
|
||||||
pub struct ImagErrorBase {
|
|
||||||
pub shortdesc : String,
|
|
||||||
pub longdesc : String,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait ImagError<'a> {
|
|
||||||
fn print(&self, rt: &Runtime);
|
|
||||||
fn print_long(&self, rt: &Runtime);
|
|
||||||
fn print_short(&self, rt: &Runtime);
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> ImagError<'a> for ImagErrorBase {
|
|
||||||
|
|
||||||
fn print(&self, rt: &Runtime) {
|
|
||||||
if self.longdesc.is_empty() {
|
|
||||||
let s = format!("Error: {}\n\n{}\n\n",
|
|
||||||
self.shortdesc, self.longdesc);
|
|
||||||
rt.print(&s)
|
|
||||||
} else {
|
|
||||||
let s = format!("Error: {}\n", self.shortdesc);
|
|
||||||
rt.print(&s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn print_short(&self, rt : &Runtime) {
|
|
||||||
rt.print(&self.shortdesc)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn print_long(&self, rt : &Runtime) {
|
|
||||||
rt.print(&self.longdesc)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -5,7 +5,6 @@ use runtime::Runtime;
|
||||||
use module::Module;
|
use module::Module;
|
||||||
|
|
||||||
mod cli;
|
mod cli;
|
||||||
mod error;
|
|
||||||
mod runtime;
|
mod runtime;
|
||||||
mod module;
|
mod module;
|
||||||
mod storage;
|
mod storage;
|
||||||
|
|
|
@ -1,35 +1,49 @@
|
||||||
use runtime::Runtime;
|
use runtime::Runtime;
|
||||||
use error::ImagErrorBase;
|
|
||||||
|
|
||||||
pub struct ModuleError {
|
pub struct ModuleError {
|
||||||
base: ImagErrorBase,
|
shortdesc : String,
|
||||||
module_name: String,
|
longdesc : String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ModuleError {
|
impl ModuleError {
|
||||||
|
|
||||||
pub fn short<T: Module>(module : &T, short : String) -> ModuleError {
|
pub fn short(short : String) -> ModuleError {
|
||||||
ModuleError::new(module, short, "".to_string())
|
ModuleError::new(short, "".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new<T: Module>(module : &T, short : String, long : String) -> ModuleError {
|
pub fn new(short : String, long : String) -> ModuleError {
|
||||||
ModuleError {
|
ModuleError {
|
||||||
base: ImagErrorBase {
|
|
||||||
shortdesc: short,
|
shortdesc: short,
|
||||||
longdesc: long,
|
longdesc: long,
|
||||||
},
|
|
||||||
module_name: module.name(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn print(&self, rt : &Runtime) {
|
||||||
|
if self.longdesc.is_empty() {
|
||||||
|
let s = format!("Error: {}\n\n{}\n\n",
|
||||||
|
self.shortdesc, self.longdesc);
|
||||||
|
rt.print(&s)
|
||||||
|
} else {
|
||||||
|
let s = format!("Error: {}\n", self.shortdesc);
|
||||||
|
rt.print(&s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn print_short(&self, rt : &Runtime) {
|
||||||
|
rt.print(&self.shortdesc)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn print_long(&self, rt : &Runtime) {
|
||||||
|
rt.print(&self.longdesc)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Module {
|
pub trait Module {
|
||||||
|
|
||||||
fn new() -> Self;
|
fn load(self, &rt : Runtime) -> Self;
|
||||||
fn load(&self, &rt : Runtime) -> Self;
|
fn name(self) -> String;
|
||||||
fn name(&self) -> String;
|
|
||||||
|
|
||||||
fn execute(&self, &rt : Runtime) -> Option<ModuleError>;
|
fn execute(self, &rt : Runtime) -> Option<ModuleError>;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue