summaryrefslogtreecommitdiff
path: root/cli/errors.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/errors.rs')
-rw-r--r--cli/errors.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/cli/errors.rs b/cli/errors.rs
index bd3e7ba73..424091584 100644
--- a/cli/errors.rs
+++ b/cli/errors.rs
@@ -4,6 +4,8 @@ pub use crate::msg::ErrorKind;
use crate::resolve_addr::ResolveAddrError;
use deno::JSError;
use hyper;
+#[cfg(unix)]
+use nix::{errno::Errno, Error as UnixError};
use std;
use std::fmt;
use std::io;
@@ -168,6 +170,32 @@ impl From<ResolveAddrError> for DenoError {
}
}
+#[cfg(unix)]
+impl From<UnixError> for DenoError {
+ fn from(e: UnixError) -> Self {
+ match e {
+ UnixError::Sys(Errno::EPERM) => Self {
+ repr: Repr::Simple(
+ ErrorKind::PermissionDenied,
+ Errno::EPERM.desc().to_owned(),
+ ),
+ },
+ UnixError::Sys(Errno::EINVAL) => Self {
+ repr: Repr::Simple(
+ ErrorKind::InvalidInput,
+ Errno::EINVAL.desc().to_owned(),
+ ),
+ },
+ UnixError::Sys(err) => Self {
+ repr: Repr::Simple(ErrorKind::UnixError, err.desc().to_owned()),
+ },
+ _ => Self {
+ repr: Repr::Simple(ErrorKind::Other, format!("{}", e)),
+ },
+ }
+ }
+}
+
pub fn bad_resource() -> DenoError {
new(ErrorKind::BadResource, String::from("bad resource id"))
}