summaryrefslogtreecommitdiff
path: root/cli/ops/os.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/ops/os.rs')
-rw-r--r--cli/ops/os.rs36
1 files changed, 20 insertions, 16 deletions
diff --git a/cli/ops/os.rs b/cli/ops/os.rs
index d1786a6db..10c5e247e 100644
--- a/cli/ops/os.rs
+++ b/cli/ops/os.rs
@@ -1,5 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
use super::dispatch_json::{Deserialize, JsonOp, Value};
+use crate::op_error::OpError;
use crate::ops::json_op;
use crate::state::State;
use atty;
@@ -31,7 +32,7 @@ fn op_get_dir(
state: &State,
args: Value,
_zero_copy: Option<ZeroCopyBuf>,
-) -> Result<JsonOp, ErrBox> {
+) -> Result<JsonOp, OpError> {
state.check_env()?;
let args: GetDirArgs = serde_json::from_value(args)?;
@@ -52,17 +53,20 @@ fn op_get_dir(
"template" => dirs::template_dir(),
"video" => dirs::video_dir(),
_ => {
- return Err(ErrBox::from(Error::new(
- ErrorKind::InvalidInput,
- format!("Invalid dir type `{}`", args.kind.as_str()),
- )))
+ return Err(
+ Error::new(
+ ErrorKind::InvalidInput,
+ format!("Invalid dir type `{}`", args.kind.as_str()),
+ )
+ .into(),
+ )
}
};
if path == None {
- Err(ErrBox::from(Error::new(
- ErrorKind::NotFound,
- format!("Could not get user {} directory.", args.kind.as_str()),
+ Err(OpError::not_found(format!(
+ "Could not get user {} directory.",
+ args.kind.as_str()
)))
} else {
Ok(JsonOp::Sync(json!(path
@@ -77,7 +81,7 @@ fn op_exec_path(
state: &State,
_args: Value,
_zero_copy: Option<ZeroCopyBuf>,
-) -> Result<JsonOp, ErrBox> {
+) -> Result<JsonOp, OpError> {
state.check_env()?;
let current_exe = env::current_exe().unwrap();
// Now apply URL parser to current exe to get fully resolved path, otherwise
@@ -97,7 +101,7 @@ fn op_set_env(
state: &State,
args: Value,
_zero_copy: Option<ZeroCopyBuf>,
-) -> Result<JsonOp, ErrBox> {
+) -> Result<JsonOp, OpError> {
let args: SetEnv = serde_json::from_value(args)?;
state.check_env()?;
env::set_var(args.key, args.value);
@@ -108,7 +112,7 @@ fn op_env(
state: &State,
_args: Value,
_zero_copy: Option<ZeroCopyBuf>,
-) -> Result<JsonOp, ErrBox> {
+) -> Result<JsonOp, OpError> {
state.check_env()?;
let v = env::vars().collect::<HashMap<String, String>>();
Ok(JsonOp::Sync(json!(v)))
@@ -123,7 +127,7 @@ fn op_get_env(
state: &State,
args: Value,
_zero_copy: Option<ZeroCopyBuf>,
-) -> Result<JsonOp, ErrBox> {
+) -> Result<JsonOp, OpError> {
let args: GetEnv = serde_json::from_value(args)?;
state.check_env()?;
let r = match env::var(args.key) {
@@ -142,7 +146,7 @@ fn op_exit(
_s: &State,
args: Value,
_zero_copy: Option<ZeroCopyBuf>,
-) -> Result<JsonOp, ErrBox> {
+) -> Result<JsonOp, OpError> {
let args: Exit = serde_json::from_value(args)?;
std::process::exit(args.code)
}
@@ -151,7 +155,7 @@ fn op_is_tty(
_s: &State,
_args: Value,
_zero_copy: Option<ZeroCopyBuf>,
-) -> Result<JsonOp, ErrBox> {
+) -> Result<JsonOp, OpError> {
Ok(JsonOp::Sync(json!({
"stdin": atty::is(atty::Stream::Stdin),
"stdout": atty::is(atty::Stream::Stdout),
@@ -163,7 +167,7 @@ fn op_loadavg(
state: &State,
_args: Value,
_zero_copy: Option<ZeroCopyBuf>,
-) -> Result<JsonOp, ErrBox> {
+) -> Result<JsonOp, OpError> {
state.check_env()?;
match sys_info::loadavg() {
Ok(loadavg) => Ok(JsonOp::Sync(json!([
@@ -179,7 +183,7 @@ fn op_hostname(
state: &State,
_args: Value,
_zero_copy: Option<ZeroCopyBuf>,
-) -> Result<JsonOp, ErrBox> {
+) -> Result<JsonOp, OpError> {
state.check_env()?;
let hostname = sys_info::hostname().unwrap_or_else(|_| "".to_owned());
Ok(JsonOp::Sync(json!(hostname)))