summaryrefslogtreecommitdiff
path: root/src/errors.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/errors.rs')
-rw-r--r--src/errors.rs13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/errors.rs b/src/errors.rs
index 1bedf8d40..872f3492e 100644
--- a/src/errors.rs
+++ b/src/errors.rs
@@ -15,15 +15,22 @@ pub struct DenoError {
#[derive(Debug)]
enum Repr {
- // Simple(ErrorKind),
+ Simple(ErrorKind, String),
IoErr(io::Error),
UrlErr(url::ParseError),
HyperErr(hyper::Error),
}
+pub fn new(kind: ErrorKind, msg: String) -> DenoError {
+ DenoError {
+ repr: Repr::Simple(kind, msg),
+ }
+}
+
impl DenoError {
pub fn kind(&self) -> ErrorKind {
match self.repr {
+ Repr::Simple(kind, ref _msg) => kind,
// Repr::Simple(kind) => kind,
Repr::IoErr(ref err) => {
use std::io::ErrorKind::*;
@@ -87,10 +94,10 @@ impl DenoError {
impl fmt::Display for DenoError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.repr {
+ Repr::Simple(_kind, ref _msg) => panic!("todo"),
Repr::IoErr(ref err) => err.fmt(f),
Repr::UrlErr(ref err) => err.fmt(f),
Repr::HyperErr(ref err) => err.fmt(f),
- // Repr::Simple(..) => Ok(()),
}
}
}
@@ -98,6 +105,7 @@ impl fmt::Display for DenoError {
impl std::error::Error for DenoError {
fn description(&self) -> &str {
match self.repr {
+ Repr::Simple(_kind, ref msg) => msg.as_str(),
Repr::IoErr(ref err) => err.description(),
Repr::UrlErr(ref err) => err.description(),
Repr::HyperErr(ref err) => err.description(),
@@ -107,6 +115,7 @@ impl std::error::Error for DenoError {
fn cause(&self) -> Option<&std::error::Error> {
match self.repr {
+ Repr::Simple(_kind, ref _msg) => None,
Repr::IoErr(ref err) => Some(err),
Repr::UrlErr(ref err) => Some(err),
Repr::HyperErr(ref err) => Some(err),