2019-05-16 00:58:44 +02:00
|
|
|
#[allow(unused)]
|
2019-05-15 20:14:51 +02:00
|
|
|
use crate::prelude::*;
|
2019-05-16 00:58:44 +02:00
|
|
|
|
2019-05-13 19:30:51 +02:00
|
|
|
use crate::Value;
|
2019-05-10 18:59:12 +02:00
|
|
|
use derive_new::new;
|
|
|
|
|
2019-05-17 17:55:50 +02:00
|
|
|
#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, new)]
|
2019-05-10 18:59:12 +02:00
|
|
|
pub struct ShellError {
|
|
|
|
title: String,
|
2019-05-13 19:30:51 +02:00
|
|
|
error: Value,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ShellError {
|
|
|
|
crate fn string(title: impl Into<String>) -> ShellError {
|
|
|
|
ShellError::new(title.into(), Value::nothing())
|
|
|
|
}
|
2019-05-15 20:14:51 +02:00
|
|
|
|
|
|
|
crate fn copy_error(&self) -> ShellError {
|
|
|
|
ShellError {
|
|
|
|
title: self.title.clone(),
|
|
|
|
error: self.error.copy(),
|
|
|
|
}
|
|
|
|
}
|
2019-05-16 23:43:36 +02:00
|
|
|
|
|
|
|
crate fn description(&self) -> String {
|
|
|
|
self.title.clone()
|
|
|
|
}
|
2019-05-10 18:59:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl std::fmt::Display for ShellError {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
|
|
write!(f, "{}", &self.title)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::error::Error for ShellError {}
|
|
|
|
|
|
|
|
impl std::convert::From<std::io::Error> for ShellError {
|
|
|
|
fn from(input: std::io::Error) -> ShellError {
|
|
|
|
ShellError {
|
|
|
|
title: format!("{}", input),
|
2019-05-13 19:30:51 +02:00
|
|
|
error: Value::nothing(),
|
2019-05-10 18:59:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|