diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2018-09-27 00:56:39 -0400 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-09-28 20:53:33 -0400 |
commit | bcbbee7399d41d813e78abe63126e2a01edb5848 (patch) | |
tree | 0c1d044bf8c441cec322d5e792ca915126cc856d /src/errors.rs | |
parent | d653808c9f4a7d09acd5f251ffc510d470d687b0 (diff) |
Adds basic File I/O and FD table.
Adds deno.stdin, deno.stdout, deno.stderr, deno.open(), deno.write(),
deno.read(), deno.Reader, deno.Writer, deno.copy().
Fixes #721. tests/cat.ts works.
Diffstat (limited to 'src/errors.rs')
-rw-r--r-- | src/errors.rs | 13 |
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), |