summaryrefslogtreecommitdiff
path: root/cli/state.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-02-23 14:51:29 -0500
committerGitHub <noreply@github.com>2020-02-23 14:51:29 -0500
commit4e1abb4f3a1fbdac25b1e7db0588572e4d5a6579 (patch)
tree644ace7dc1acac7b09bfab037e0ca589fa11987b /cli/state.rs
parent45eb2f9b37c2c7498c58eb45f76667aaa4a7d731 (diff)
refactor: use OpError instead of ErrBox for errors in ops (#4058)
To better reflect changes in error types in JS from #3662 this PR changes default error type used in ops from "ErrBox" to "OpError". "OpError" is a type that can be sent over to JSON; it has all information needed to construct error in JavaScript. That made "GetErrorKind" trait useless and so it was removed altogether. To provide compatibility with previous use of "ErrBox" an implementation of "From<ErrBox> for OpError" was added, however, it is an escape hatch and ops implementors should strive to use "OpError" directly.
Diffstat (limited to 'cli/state.rs')
-rw-r--r--cli/state.rs28
1 files changed, 14 insertions, 14 deletions
diff --git a/cli/state.rs b/cli/state.rs
index 7f342a9b1..4e822f6a9 100644
--- a/cli/state.rs
+++ b/cli/state.rs
@@ -1,10 +1,10 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
use crate::compilers::TargetLib;
-use crate::deno_error::permission_denied;
use crate::global_state::GlobalState;
use crate::global_timer::GlobalTimer;
use crate::import_map::ImportMap;
use crate::metrics::Metrics;
+use crate::op_error::OpError;
use crate::ops::JsonOp;
use crate::ops::MinimalOp;
use crate::permissions::DenoPermissions;
@@ -128,15 +128,15 @@ impl State {
pub fn stateful_op<D>(
&self,
dispatcher: D,
- ) -> impl Fn(Value, Option<ZeroCopyBuf>) -> Result<JsonOp, ErrBox>
+ ) -> impl Fn(Value, Option<ZeroCopyBuf>) -> Result<JsonOp, OpError>
where
- D: Fn(&State, Value, Option<ZeroCopyBuf>) -> Result<JsonOp, ErrBox>,
+ D: Fn(&State, Value, Option<ZeroCopyBuf>) -> Result<JsonOp, OpError>,
{
let state = self.clone();
move |args: Value,
zero_copy: Option<ZeroCopyBuf>|
- -> Result<JsonOp, ErrBox> { dispatcher(&state, args, zero_copy) }
+ -> Result<JsonOp, OpError> { dispatcher(&state, args, zero_copy) }
}
}
@@ -171,7 +171,7 @@ impl Loader for State {
let module_specifier = module_specifier.clone();
if is_dyn_import {
if let Err(e) = self.check_dyn_import(&module_specifier) {
- return async move { Err(e) }.boxed_local();
+ return async move { Err(e.into()) }.boxed_local();
}
}
@@ -278,44 +278,44 @@ impl State {
}
#[inline]
- pub fn check_read(&self, path: &Path) -> Result<(), ErrBox> {
+ pub fn check_read(&self, path: &Path) -> Result<(), OpError> {
self.borrow().permissions.check_read(path)
}
#[inline]
- pub fn check_write(&self, path: &Path) -> Result<(), ErrBox> {
+ pub fn check_write(&self, path: &Path) -> Result<(), OpError> {
self.borrow().permissions.check_write(path)
}
#[inline]
- pub fn check_env(&self) -> Result<(), ErrBox> {
+ pub fn check_env(&self) -> Result<(), OpError> {
self.borrow().permissions.check_env()
}
#[inline]
- pub fn check_net(&self, hostname: &str, port: u16) -> Result<(), ErrBox> {
+ pub fn check_net(&self, hostname: &str, port: u16) -> Result<(), OpError> {
self.borrow().permissions.check_net(hostname, port)
}
#[inline]
- pub fn check_net_url(&self, url: &url::Url) -> Result<(), ErrBox> {
+ pub fn check_net_url(&self, url: &url::Url) -> Result<(), OpError> {
self.borrow().permissions.check_net_url(url)
}
#[inline]
- pub fn check_run(&self) -> Result<(), ErrBox> {
+ pub fn check_run(&self) -> Result<(), OpError> {
self.borrow().permissions.check_run()
}
#[inline]
- pub fn check_plugin(&self, filename: &Path) -> Result<(), ErrBox> {
+ pub fn check_plugin(&self, filename: &Path) -> Result<(), OpError> {
self.borrow().permissions.check_plugin(filename)
}
pub fn check_dyn_import(
&self,
module_specifier: &ModuleSpecifier,
- ) -> Result<(), ErrBox> {
+ ) -> Result<(), OpError> {
let u = module_specifier.as_url();
match u.scheme() {
"http" | "https" => {
@@ -332,7 +332,7 @@ impl State {
self.check_read(Path::new(&path))?;
Ok(())
}
- _ => Err(permission_denied()),
+ _ => unreachable!(),
}
}