summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2021-11-16 09:02:28 -0500
committerGitHub <noreply@github.com>2021-11-16 09:02:28 -0500
commitb2036a4db71afd67a78f932528143fb07faea538 (patch)
treea78612e8868609af7aa6fe9ecf49d3ab0c42c9da
parentf9f9ddc5e308809343bbf5c07d4487df5a1b93cf (diff)
refactor: re-export anyhow from deno_core (#12777)
-rw-r--r--cli/ast/mod.rs2
-rw-r--r--cli/config_file.rs4
-rw-r--r--cli/emit.rs4
-rw-r--r--cli/fs_util.rs2
-rw-r--r--cli/lsp/analysis.rs2
-rw-r--r--cli/lsp/cache.rs2
-rw-r--r--cli/lsp/config.rs2
-rw-r--r--cli/lsp/diagnostics.rs2
-rw-r--r--cli/lsp/language_server.rs2
-rw-r--r--cli/lsp/path_to_regex.rs2
-rw-r--r--cli/lsp/registries.rs4
-rw-r--r--cli/lsp/tsc.rs2
-rw-r--r--cli/ops/runtime_compiler.rs2
-rw-r--r--cli/proc_state.rs4
-rw-r--r--cli/standalone.rs4
-rw-r--r--cli/tools/lint.rs5
-rw-r--r--cli/tools/standalone.rs2
-rw-r--r--cli/tools/upgrade.rs2
-rw-r--r--cli/tsc.rs4
-rw-r--r--core/async_cancel.rs4
-rw-r--r--core/bindings.rs8
-rw-r--r--core/error.rs48
-rw-r--r--core/error_codes.rs4
-rw-r--r--core/examples/http_bench_json_ops.rs26
-rw-r--r--core/extensions.rs13
-rw-r--r--core/inspector.rs4
-rw-r--r--core/lib.rs1
-rw-r--r--core/modules.rs50
-rw-r--r--core/ops.rs10
-rw-r--r--core/ops_builtin.rs24
-rw-r--r--core/ops_json.rs14
-rw-r--r--core/resources.rs17
-rw-r--r--core/runtime.rs62
-rw-r--r--ext/tls/lib.rs2
-rw-r--r--runtime/fs_util.rs2
-rw-r--r--runtime/ops/runtime.rs2
36 files changed, 165 insertions, 179 deletions
diff --git a/cli/ast/mod.rs b/cli/ast/mod.rs
index a6cd86552..ac3dd5887 100644
--- a/cli/ast/mod.rs
+++ b/cli/ast/mod.rs
@@ -32,7 +32,7 @@ use deno_ast::Diagnostic;
use deno_ast::LineAndColumnDisplay;
use deno_ast::MediaType;
use deno_ast::ParsedSource;
-use deno_core::error::anyhow;
+use deno_core::anyhow::anyhow;
use deno_core::error::AnyError;
use deno_core::resolve_url_or_path;
use deno_core::serde_json;
diff --git a/cli/config_file.rs b/cli/config_file.rs
index 20e254dd0..d61eb2346 100644
--- a/cli/config_file.rs
+++ b/cli/config_file.rs
@@ -2,10 +2,10 @@
use crate::fs_util::canonicalize_path;
-use deno_core::error::anyhow;
+use deno_core::anyhow::anyhow;
+use deno_core::anyhow::Context;
use deno_core::error::custom_error;
use deno_core::error::AnyError;
-use deno_core::error::Context;
use deno_core::serde::Deserialize;
use deno_core::serde::Serialize;
use deno_core::serde::Serializer;
diff --git a/cli/emit.rs b/cli/emit.rs
index a189b8202..9eac892ff 100644
--- a/cli/emit.rs
+++ b/cli/emit.rs
@@ -16,9 +16,9 @@ use crate::tsc;
use crate::version;
use deno_ast::swc;
-use deno_core::error::anyhow;
+use deno_core::anyhow::anyhow;
+use deno_core::anyhow::Context;
use deno_core::error::AnyError;
-use deno_core::error::Context;
use deno_core::serde::Deserialize;
use deno_core::serde::Deserializer;
use deno_core::serde::Serialize;
diff --git a/cli/fs_util.rs b/cli/fs_util.rs
index 21a9a6aad..0602994e3 100644
--- a/cli/fs_util.rs
+++ b/cli/fs_util.rs
@@ -1,7 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
+use deno_core::anyhow::Context;
use deno_core::error::AnyError;
-use deno_core::error::Context;
pub use deno_core::normalize_path;
use deno_core::ModuleSpecifier;
use deno_runtime::deno_crypto::rand;
diff --git a/cli/lsp/analysis.rs b/cli/lsp/analysis.rs
index 011ffa757..18d675109 100644
--- a/cli/lsp/analysis.rs
+++ b/cli/lsp/analysis.rs
@@ -8,7 +8,7 @@ use crate::tools::lint::create_linter;
use crate::tools::lint::get_configured_rules;
use deno_ast::SourceTextInfo;
-use deno_core::error::anyhow;
+use deno_core::anyhow::anyhow;
use deno_core::error::custom_error;
use deno_core::error::AnyError;
use deno_core::serde::Deserialize;
diff --git a/cli/lsp/cache.rs b/cli/lsp/cache.rs
index b7bdb90c5..247128420 100644
--- a/cli/lsp/cache.rs
+++ b/cli/lsp/cache.rs
@@ -8,7 +8,7 @@ use crate::proc_state::ProcState;
use crate::resolver::ImportMapResolver;
use crate::resolver::JsxResolver;
-use deno_core::error::anyhow;
+use deno_core::anyhow::anyhow;
use deno_core::error::AnyError;
use deno_core::ModuleSpecifier;
use deno_runtime::permissions::Permissions;
diff --git a/cli/lsp/config.rs b/cli/lsp/config.rs
index af2caf22a..27efaf497 100644
--- a/cli/lsp/config.rs
+++ b/cli/lsp/config.rs
@@ -1,6 +1,6 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
-use deno_core::error::anyhow;
+use deno_core::anyhow::anyhow;
use deno_core::error::AnyError;
use deno_core::parking_lot::RwLock;
use deno_core::serde::Deserialize;
diff --git a/cli/lsp/diagnostics.rs b/cli/lsp/diagnostics.rs
index f14d80cd8..f84d22b45 100644
--- a/cli/lsp/diagnostics.rs
+++ b/cli/lsp/diagnostics.rs
@@ -8,7 +8,7 @@ use super::tsc;
use crate::diagnostics;
-use deno_core::error::anyhow;
+use deno_core::anyhow::anyhow;
use deno_core::error::AnyError;
use deno_core::resolve_url;
use deno_core::serde_json::json;
diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs
index 10a69fadb..dbe00861e 100644
--- a/cli/lsp/language_server.rs
+++ b/cli/lsp/language_server.rs
@@ -1,7 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
use deno_ast::MediaType;
-use deno_core::error::anyhow;
+use deno_core::anyhow::anyhow;
use deno_core::error::AnyError;
use deno_core::resolve_url;
use deno_core::serde_json;
diff --git a/cli/lsp/path_to_regex.rs b/cli/lsp/path_to_regex.rs
index 6e0ed3390..ce935ee27 100644
--- a/cli/lsp/path_to_regex.rs
+++ b/cli/lsp/path_to_regex.rs
@@ -26,7 +26,7 @@
// THE SOFTWARE.
//
-use deno_core::error::anyhow;
+use deno_core::anyhow::anyhow;
use deno_core::error::AnyError;
use fancy_regex::Regex as FancyRegex;
use regex::Regex;
diff --git a/cli/lsp/registries.rs b/cli/lsp/registries.rs
index bef55150d..c8ab5d586 100644
--- a/cli/lsp/registries.rs
+++ b/cli/lsp/registries.rs
@@ -15,9 +15,9 @@ use crate::file_fetcher::CacheSetting;
use crate::file_fetcher::FileFetcher;
use crate::http_cache::HttpCache;
-use deno_core::error::anyhow;
+use deno_core::anyhow::anyhow;
+use deno_core::anyhow::Context;
use deno_core::error::AnyError;
-use deno_core::error::Context;
use deno_core::resolve_url;
use deno_core::serde::Deserialize;
use deno_core::serde_json;
diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs
index 9350d6f19..b5ce48fab 100644
--- a/cli/lsp/tsc.rs
+++ b/cli/lsp/tsc.rs
@@ -19,7 +19,7 @@ use crate::config_file::TsConfig;
use crate::tsc;
use crate::tsc::ResolveArgs;
-use deno_core::error::anyhow;
+use deno_core::anyhow::anyhow;
use deno_core::error::custom_error;
use deno_core::error::AnyError;
use deno_core::located_script_name;
diff --git a/cli/ops/runtime_compiler.rs b/cli/ops/runtime_compiler.rs
index b16fbcf69..145da4c1d 100644
--- a/cli/ops/runtime_compiler.rs
+++ b/cli/ops/runtime_compiler.rs
@@ -9,10 +9,10 @@ use crate::proc_state::ProcState;
use crate::resolver::ImportMapResolver;
use crate::resolver::JsxResolver;
+use deno_core::anyhow::Context;
use deno_core::error::custom_error;
use deno_core::error::generic_error;
use deno_core::error::AnyError;
-use deno_core::error::Context;
use deno_core::resolve_url_or_path;
use deno_core::serde_json;
use deno_core::serde_json::Value;
diff --git a/cli/proc_state.rs b/cli/proc_state.rs
index 7a42b6219..8a3864d39 100644
--- a/cli/proc_state.rs
+++ b/cli/proc_state.rs
@@ -21,10 +21,10 @@ use crate::resolver::JsxResolver;
use crate::source_maps::SourceMapGetter;
use crate::version;
-use deno_core::error::anyhow;
+use deno_core::anyhow::anyhow;
+use deno_core::anyhow::Context;
use deno_core::error::custom_error;
use deno_core::error::AnyError;
-use deno_core::error::Context;
use deno_core::parking_lot::Mutex;
use deno_core::resolve_url;
use deno_core::url::Url;
diff --git a/cli/standalone.rs b/cli/standalone.rs
index e0190920f..92e7dfbae 100644
--- a/cli/standalone.rs
+++ b/cli/standalone.rs
@@ -6,10 +6,10 @@ use crate::flags::Flags;
use crate::ops;
use crate::proc_state::ProcState;
use crate::version;
-use deno_core::error::anyhow;
+use deno_core::anyhow::anyhow;
+use deno_core::anyhow::Context;
use deno_core::error::type_error;
use deno_core::error::AnyError;
-use deno_core::error::Context;
use deno_core::futures::FutureExt;
use deno_core::located_script_name;
use deno_core::resolve_url;
diff --git a/cli/tools/lint.rs b/cli/tools/lint.rs
index 4a1f25dd4..ec42adc34 100644
--- a/cli/tools/lint.rs
+++ b/cli/tools/lint.rs
@@ -14,7 +14,10 @@ use crate::fs_util::{collect_files, is_supported_ext};
use crate::tools::fmt::run_parallelized;
use crate::{colors, file_watcher};
use deno_ast::MediaType;
-use deno_core::error::{anyhow, generic_error, AnyError, JsStackFrame};
+use deno_core::anyhow::anyhow;
+use deno_core::error::generic_error;
+use deno_core::error::AnyError;
+use deno_core::error::JsStackFrame;
use deno_core::serde_json;
use deno_lint::diagnostic::LintDiagnostic;
use deno_lint::linter::Linter;
diff --git a/cli/tools/standalone.rs b/cli/tools/standalone.rs
index fb07254aa..5dd6f23ad 100644
--- a/cli/tools/standalone.rs
+++ b/cli/tools/standalone.rs
@@ -4,7 +4,7 @@ use crate::deno_dir::DenoDir;
use crate::flags::DenoSubcommand;
use crate::flags::Flags;
use crate::flags::RunFlags;
-use deno_core::error::bail;
+use deno_core::anyhow::bail;
use deno_core::error::AnyError;
use deno_core::serde_json;
use deno_runtime::deno_fetch::reqwest::Client;
diff --git a/cli/tools/upgrade.rs b/cli/tools/upgrade.rs
index 6de8ba932..5838cb290 100644
--- a/cli/tools/upgrade.rs
+++ b/cli/tools/upgrade.rs
@@ -2,7 +2,7 @@
//! This module provides feature to upgrade deno executable
-use deno_core::error::bail;
+use deno_core::anyhow::bail;
use deno_core::error::AnyError;
use deno_core::futures::StreamExt;
use deno_runtime::deno_fetch::reqwest;
diff --git a/cli/tsc.rs b/cli/tsc.rs
index 5f5c09539..184fbd144 100644
--- a/cli/tsc.rs
+++ b/cli/tsc.rs
@@ -5,9 +5,9 @@ use crate::diagnostics::Diagnostics;
use crate::emit;
use deno_ast::MediaType;
-use deno_core::error::anyhow;
+use deno_core::anyhow::anyhow;
+use deno_core::anyhow::Context;
use deno_core::error::AnyError;
-use deno_core::error::Context;
use deno_core::located_script_name;
use deno_core::op_sync;
use deno_core::resolve_url_or_path;
diff --git a/core/async_cancel.rs b/core/async_cancel.rs
index e3110bf13..ab7ec2248 100644
--- a/core/async_cancel.rs
+++ b/core/async_cancel.rs
@@ -537,7 +537,7 @@ mod internal {
#[cfg(test)]
mod tests {
use super::*;
- use crate::error::AnyError;
+ use anyhow::Error;
use futures::future::pending;
use futures::future::poll_fn;
use futures::future::ready;
@@ -652,7 +652,7 @@ mod tests {
// Cancel a spawned task before it actually runs.
let cancel_handle = Rc::new(CancelHandle::new());
let future = spawn(async { panic!("the task should not be spawned") })
- .map_err(AnyError::from)
+ .map_err(Error::from)
.try_or_cancel(&cancel_handle);
cancel_handle.cancel();
let error = future.await.unwrap_err();
diff --git a/core/bindings.rs b/core/bindings.rs
index 10daee27a..63c7ea4b9 100644
--- a/core/bindings.rs
+++ b/core/bindings.rs
@@ -1,7 +1,6 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
use crate::error::is_instance_of_error;
-use crate::error::AnyError;
use crate::modules::ModuleMap;
use crate::resolve_url_or_path;
use crate::JsRuntime;
@@ -12,6 +11,7 @@ use crate::OpResult;
use crate::OpTable;
use crate::PromiseId;
use crate::ZeroCopyBuf;
+use anyhow::Error;
use log::debug;
use serde::Deserialize;
use serde::Serialize;
@@ -322,7 +322,7 @@ fn opcall_sync<'s>(
let op_id = match v8::Local::<v8::Integer>::try_from(args.get(0))
.map(|l| l.value() as OpId)
- .map_err(AnyError::from)
+ .map_err(Error::from)
{
Ok(op_id) => op_id,
Err(err) => {
@@ -379,7 +379,7 @@ fn opcall_async<'s>(
let op_id = match v8::Local::<v8::Integer>::try_from(args.get(0))
.map(|l| l.value() as OpId)
- .map_err(AnyError::from)
+ .map_err(Error::from)
{
Ok(op_id) => op_id,
Err(err) => {
@@ -392,7 +392,7 @@ fn opcall_async<'s>(
let arg1 = args.get(1);
let promise_id = v8::Local::<v8::Integer>::try_from(arg1)
.map(|l| l.value() as PromiseId)
- .map_err(AnyError::from);
+ .map_err(Error::from);
// Fail if promise id invalid (not an int)
let promise_id: PromiseId = match promise_id {
Ok(promise_id) => promise_id,
diff --git a/core/error.rs b/core/error.rs
index 793a42603..e8c0305d4 100644
--- a/core/error.rs
+++ b/core/error.rs
@@ -1,23 +1,21 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
-pub use anyhow::anyhow;
-pub use anyhow::bail;
-pub use anyhow::Context;
+use anyhow::Error;
use std::borrow::Cow;
-use std::error::Error;
use std::fmt;
use std::fmt::Debug;
use std::fmt::Display;
use std::fmt::Formatter;
/// A generic wrapper that can encapsulate any concrete error type.
+// TODO(ry) Deprecate AnyError and encourage deno_core::anyhow::Error instead.
pub type AnyError = anyhow::Error;
/// Creates a new error with a caller-specified error class name and message.
pub fn custom_error(
class: &'static str,
message: impl Into<Cow<'static, str>>,
-) -> AnyError {
+) -> Error {
CustomError {
class,
message: message.into(),
@@ -25,39 +23,39 @@ pub fn custom_error(
.into()
}
-pub fn generic_error(message: impl Into<Cow<'static, str>>) -> AnyError {
+pub fn generic_error(message: impl Into<Cow<'static, str>>) -> Error {
custom_error("Error", message)
}
-pub fn type_error(message: impl Into<Cow<'static, str>>) -> AnyError {
+pub fn type_error(message: impl Into<Cow<'static, str>>) -> Error {
custom_error("TypeError", message)
}
-pub fn range_error(message: impl Into<Cow<'static, str>>) -> AnyError {
+pub fn range_error(message: impl Into<Cow<'static, str>>) -> Error {
custom_error("RangeError", message)
}
-pub fn invalid_hostname(hostname: &str) -> AnyError {
+pub fn invalid_hostname(hostname: &str) -> Error {
type_error(format!("Invalid hostname: '{}'", hostname))
}
-pub fn uri_error(message: impl Into<Cow<'static, str>>) -> AnyError {
+pub fn uri_error(message: impl Into<Cow<'static, str>>) -> Error {
custom_error("URIError", message)
}
-pub fn bad_resource(message: impl Into<Cow<'static, str>>) -> AnyError {
+pub fn bad_resource(message: impl Into<Cow<'static, str>>) -> Error {
custom_error("BadResource", message)
}
-pub fn bad_resource_id() -> AnyError {
+pub fn bad_resource_id() -> Error {
custom_error("BadResource", "Bad resource ID")
}
-pub fn not_supported() -> AnyError {
+pub fn not_supported() -> Error {
custom_error("NotSupported", "The operation is not supported")
}
-pub fn resource_unavailable() -> AnyError {
+pub fn resource_unavailable() -> Error {
custom_error(
"Busy",
"Resource is unavailable because it is in use by a promise",
@@ -66,7 +64,7 @@ pub fn resource_unavailable() -> AnyError {
/// A simple error type that lets the creator specify both the error message and
/// the error class name. This type is private; externally it only ever appears
-/// wrapped in an `AnyError`. To retrieve the error class name from a wrapped
+/// wrapped in an `anyhow::Error`. To retrieve the error class name from a wrapped
/// `CustomError`, use the function `get_custom_error_class()`.
#[derive(Debug)]
struct CustomError {
@@ -80,11 +78,11 @@ impl Display for CustomError {
}
}
-impl Error for CustomError {}
+impl std::error::Error for CustomError {}
/// If this error was crated with `custom_error()`, return the specified error
/// class name. In all other cases this function returns `None`.
-pub fn get_custom_error_class(error: &AnyError) -> Option<&'static str> {
+pub fn get_custom_error_class(error: &Error) -> Option<&'static str> {
error.downcast_ref::<CustomError>().map(|e| e.class)
}
@@ -168,7 +166,7 @@ struct NativeJsError {
}
impl JsError {
- pub(crate) fn create(js_error: Self) -> AnyError {
+ pub(crate) fn create(js_error: Self) -> Error {
js_error.into()
}
@@ -245,7 +243,7 @@ impl JsError {
}
}
-impl Error for JsError {}
+impl std::error::Error for JsError {}
fn format_source_loc(
file_name: &str,
@@ -283,9 +281,9 @@ impl Display for JsError {
pub(crate) fn attach_handle_to_error(
scope: &mut v8::Isolate,
- err: AnyError,
+ err: Error,
handle: v8::Local<v8::Value>,
-) -> AnyError {
+) -> Error {
ErrWithV8Handle::new(scope, err, handle).into()
}
@@ -323,14 +321,14 @@ pub(crate) fn is_instance_of_error<'s>(
// TODO(piscisaureus): rusty_v8 should implement the Error trait on
// values of type v8::Global<T>.
pub(crate) struct ErrWithV8Handle {
- err: AnyError,
+ err: Error,
handle: v8::Global<v8::Value>,
}
impl ErrWithV8Handle {
pub fn new(
scope: &mut v8::Isolate,
- err: AnyError,
+ err: Error,
handle: v8::Local<v8::Value>,
) -> Self {
let handle = v8::Global::new(scope, handle);
@@ -348,11 +346,11 @@ impl ErrWithV8Handle {
unsafe impl Send for ErrWithV8Handle {}
unsafe impl Sync for ErrWithV8Handle {}
-impl Error for ErrWithV8Handle {}
+impl std::error::Error for ErrWithV8Handle {}
impl Display for ErrWithV8Handle {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
- <AnyError as Display>::fmt(&self.err, f)
+ <Error as Display>::fmt(&self.err, f)
}
}
diff --git a/core/error_codes.rs b/core/error_codes.rs
index fc613426f..43a6c4391 100644
--- a/core/error_codes.rs
+++ b/core/error_codes.rs
@@ -1,6 +1,6 @@
-use crate::error::AnyError;
+use anyhow::Error;
-pub(crate) fn get_error_code(err: &AnyError) -> Option<&'static str> {
+pub(crate) fn get_error_code(err: &Error) -> Option<&'static str> {
err
.downcast_ref::<std::io::Error>()
.map(|e| match e.raw_os_error() {
diff --git a/core/examples/http_bench_json_ops.rs b/core/examples/http_bench_json_ops.rs
index 6f14f558c..641483b0b 100644
--- a/core/examples/http_bench_json_ops.rs
+++ b/core/examples/http_bench_json_ops.rs
@@ -1,5 +1,5 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
-use deno_core::error::AnyError;
+use deno_core::anyhow::Error;
use deno_core::AsyncRefCell;
use deno_core::AsyncResult;
use deno_core::CancelHandle;
@@ -12,7 +12,6 @@ use deno_core::ResourceId;
use deno_core::ZeroCopyBuf;
use std::cell::RefCell;
use std::env;
-use std::io::Error;
use std::net::SocketAddr;
use std::rc::Rc;
use tokio::io::AsyncReadExt;
@@ -43,7 +42,7 @@ struct TcpListener {
}
impl TcpListener {
- async fn accept(self: Rc<Self>) -> Result<TcpStream, Error> {
+ async fn accept(self: Rc<Self>) -> Result<TcpStream, std::io::Error> {
let cancel = RcRef::map(&self, |r| &r.cancel);
let stream = self.inner.accept().try_or_cancel(cancel).await?.0.into();
Ok(stream)
@@ -57,7 +56,7 @@ impl Resource for TcpListener {
}
impl TryFrom<std::net::TcpListener> for TcpListener {
- type Error = Error;
+ type Error = std::io::Error;
fn try_from(
std_listener: std::net::TcpListener,
) -> Result<Self, Self::Error> {
@@ -78,21 +77,18 @@ struct TcpStream {
}
impl TcpStream {
- async fn read(
- self: Rc<Self>,
- mut buf: ZeroCopyBuf,
- ) -> Result<usize, AnyError> {
+ async fn read(self: Rc<Self>, mut buf: ZeroCopyBuf) -> Result<usize, Error> {
let mut rd = RcRef::map(&self, |r| &r.rd).borrow_mut().await;
let cancel = RcRef::map(self, |r| &r.cancel);
rd.read(&mut buf)
.try_or_cancel(cancel)
.await
- .map_err(AnyError::from)
+ .map_err(Error::from)
}
- async fn write(self: Rc<Self>, buf: ZeroCopyBuf) -> Result<usize, AnyError> {
+ async fn write(self: Rc<Self>, buf: ZeroCopyBuf) -> Result<usize, Error> {
let mut wr = RcRef::map(self, |r| &r.wr).borrow_mut().await;
- wr.write(&buf).await.map_err(AnyError::from)
+ wr.write(&buf).await.map_err(Error::from)
}
}
@@ -129,11 +125,7 @@ fn create_js_runtime() -> JsRuntime {
runtime
}
-fn op_listen(
- state: &mut OpState,
- _: (),
- _: (),
-) -> Result<ResourceId, AnyError> {
+fn op_listen(state: &mut OpState, _: (), _: ()) -> Result<ResourceId, Error> {
log::debug!("listen");
let addr = "127.0.0.1:4544".parse::<SocketAddr>().unwrap();
let std_listener = std::net::TcpListener::bind(&addr)?;
@@ -147,7 +139,7 @@ async fn op_accept(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
_: (),
-) -> Result<ResourceId, AnyError> {
+) -> Result<ResourceId, Error> {
log::debug!("accept rid={}", rid);
let listener = state.borrow().resource_table.get::<TcpListener>(rid)?;
diff --git a/core/extensions.rs b/core/extensions.rs
index 54d648071..587a2d061 100644
--- a/core/extensions.rs
+++ b/core/extensions.rs
@@ -1,11 +1,12 @@
-use crate::error::AnyError;
-use crate::{OpFn, OpState};
+use crate::OpFn;
+use crate::OpState;
+use anyhow::Error;
pub type SourcePair = (&'static str, Box<SourceLoadFn>);
-pub type SourceLoadFn = dyn Fn() -> Result<String, AnyError>;
+pub type SourceLoadFn = dyn Fn() -> Result<String, Error>;
pub type OpPair = (&'static str, Box<OpFn>);
pub type OpMiddlewareFn = dyn Fn(&'static str, Box<OpFn>) -> Box<OpFn>;
-pub type OpStateFn = dyn Fn(&mut OpState) -> Result<(), AnyError>;
+pub type OpStateFn = dyn Fn(&mut OpState) -> Result<(), Error>;
#[derive(Default)]
pub struct Extension {
@@ -44,7 +45,7 @@ impl Extension {
}
/// Allows setting up the initial op-state of an isolate at startup.
- pub fn init_state(&self, state: &mut OpState) -> Result<(), AnyError> {
+ pub fn init_state(&self, state: &mut OpState) -> Result<(), Error> {
match &self.opstate_fn {
Some(ofn) => ofn(state),
None => Ok(()),
@@ -79,7 +80,7 @@ impl ExtensionBuilder {
pub fn state<F>(&mut self, opstate_fn: F) -> &mut Self
where
- F: Fn(&mut OpState) -> Result<(), AnyError> + 'static,
+ F: Fn(&mut OpState) -> Result<(), Error> + 'static,
{
self.state = Some(Box::new(opstate_fn));
self
diff --git a/core/inspector.rs b/core/inspector.rs
index 3e84bcd58..8a686dc63 100644
--- a/core/inspector.rs
+++ b/core/inspector.rs
@@ -5,7 +5,6 @@
//! <https://hyperandroid.com/2020/02/12/v8-inspector-from-an-embedder-standpoint/>
use crate::error::generic_error;
-use crate::error::AnyError;
use crate::futures::channel::mpsc;
use crate::futures::channel::mpsc::UnboundedReceiver;
use crate::futures::channel::mpsc::UnboundedSender;
@@ -22,6 +21,7 @@ use crate::futures::task::Poll;
use crate::serde_json;
use crate::serde_json::json;
use crate::serde_json::Value;
+use anyhow::Error;
use parking_lot::Mutex;
use std::cell::BorrowMutError;
use std::cell::RefCell;
@@ -637,7 +637,7 @@ impl LocalInspectorSession {
&mut self,
method: &str,
params: Option<serde_json::Value>,
- ) -> Result<serde_json::Value, AnyError> {
+ ) -> Result<serde_json::Value, Error> {
let id = self.next_message_id;
self.next_message_id += 1;
diff --git a/core/lib.rs b/core/lib.rs
index ceb2b89af..87994720f 100644
--- a/core/lib.rs
+++ b/core/lib.rs
@@ -19,6 +19,7 @@ mod resources;
mod runtime;
// Re-exports
+pub use anyhow;
pub use futures;
pub use parking_lot;
pub use serde;
diff --git a/core/modules.rs b/core/modules.rs
index dc2e5bb32..bc3885a7b 100644
--- a/core/modules.rs
+++ b/core/modules.rs
@@ -2,10 +2,10 @@
use crate::bindings;
use crate::error::generic_error;
-use crate::error::AnyError;
use crate::module_specifier::ModuleSpecifier;
use crate::runtime::exception_to_err_result;
use crate::OpState;
+use anyhow::Error;
use futures::future::FutureExt;
use futures::stream::FuturesUnordered;
use futures::stream::Stream;
@@ -54,9 +54,8 @@ pub struct ModuleSource {
}
pub type PrepareLoadFuture =
- dyn Future<Output = (ModuleLoadId, Result<RecursiveModuleLoad, AnyError>)>;
-pub type ModuleSourceFuture =
- dyn Future<Output = Result<ModuleSource, AnyError>>;
+ dyn Future<Output = (ModuleLoadId, Result<RecursiveModuleLoad, Error>)>;
+pub type ModuleSourceFuture = dyn Future<Output = Result<ModuleSource, Error>>;
pub trait ModuleLoader {
/// Returns an absolute URL.
@@ -71,7 +70,7 @@ pub trait ModuleLoader {
specifier: &str,
referrer: &str,
_is_main: bool,
- ) -> Result<ModuleSpecifier, AnyError>;
+ ) -> Result<ModuleSpecifier, Error>;
/// Given ModuleSpecifier, load its source code.
///
@@ -99,7 +98,7 @@ pub trait ModuleLoader {
_module_specifier: &ModuleSpecifier,
_maybe_referrer: Option<String>,
_is_dyn_import: bool,
- ) -> Pin<Box<dyn Future<Output = Result<(), AnyError>>>> {
+ ) -> Pin<Box<dyn Future<Output = Result<(), Error>>>> {
async { Ok(()) }.boxed_local()
}
}
@@ -114,7 +113,7 @@ impl ModuleLoader for NoopModuleLoader {
_specifier: &str,
_referrer: &str,
_is_main: bool,
- ) -> Result<ModuleSpecifier, AnyError> {
+ ) -> Result<ModuleSpecifier, Error> {
Err(generic_error("Module loading is not supported"))
}
@@ -142,7 +141,7 @@ impl ModuleLoader for FsModuleLoader {
specifier: &str,
referrer: &str,
_is_main: bool,
- ) -> Result<ModuleSpecifier, AnyError> {
+ ) -> Result<ModuleSpecifier, Error> {
Ok(crate::resolve_import(specifier, referrer)?)
}
@@ -257,7 +256,7 @@ impl RecursiveModuleLoad {
load
}
- pub fn resolve_root(&self) -> Result<ModuleSpecifier, AnyError> {
+ pub fn resolve_root(&self) -> Result<ModuleSpecifier, Error> {
match self.init {
LoadInit::Main(ref specifier) => {
self.loader.resolve(specifier, ".", true)
@@ -271,7 +270,7 @@ impl RecursiveModuleLoad {
}
}
- pub async fn prepare(&self) -> Result<(), AnyError> {
+ pub async fn prepare(&self) -> Result<(), Error> {
let op_state = self.op_state.clone();
let (module_specifier, maybe_referrer) = match self.init {
LoadInit::Main(ref specifier) => {
@@ -310,7 +309,7 @@ impl RecursiveModuleLoad {
&mut self,
scope: &mut v8::HandleScope,
module_source: &ModuleSource,
- ) -> Result<(), AnyError> {
+ ) -> Result<(), Error> {
// Register the module in the module map unless it's already there. If the
// specified URL and the "true" URL are different, register the alias.
if module_source.module_url_specified != module_source.module_url_found {
@@ -392,7 +391,7 @@ impl RecursiveModuleLoad {
}
impl Stream for RecursiveModuleLoad {
- type Item = Result<ModuleSource, AnyError>;
+ type Item = Result<ModuleSource, Error>;
fn poll_next(
self: Pin<&mut Self>,
@@ -529,7 +528,7 @@ impl ModuleMap {
main: bool,
name: &str,
source: &str,
- ) -> Result<ModuleId, AnyError> {
+ ) -> Result<ModuleId, Error> {
let name_str = v8::String::new(scope, name).unwrap();
let source_str = v8::String::new(scope, source).unwrap();
@@ -637,7 +636,7 @@ impl ModuleMap {
pub async fn load_main(
module_map_rc: Rc<RefCell<ModuleMap>>,
specifier: &str,
- ) -> Result<RecursiveModuleLoad, AnyError> {
+ ) -> Result<RecursiveModuleLoad, Error> {
let load = RecursiveModuleLoad::main(specifier, module_map_rc.clone());
load.prepare().await?;
Ok(load)
@@ -646,7 +645,7 @@ impl ModuleMap {
pub async fn load_side(
module_map_rc: Rc<RefCell<ModuleMap>>,
specifier: &str,
- ) -> Result<RecursiveModuleLoad, AnyError> {
+ ) -> Result<RecursiveModuleLoad, Error> {
let load = RecursiveModuleLoad::side(specifier, module_map_rc.clone());
load.prepare().await?;
Ok(load)
@@ -727,7 +726,6 @@ mod tests {
use crate::RuntimeOptions;
use futures::future::FutureExt;
use parking_lot::Mutex;
- use std::error::Error;
use std::fmt;
use std::future::Future;
use std::io;
@@ -791,8 +789,8 @@ mod tests {
}
}
- impl Error for MockError {
- fn cause(&self) -> Option<&dyn Error> {
+ impl std::error::Error for MockError {
+ fn cause(&self) -> Option<&dyn std::error::Error> {
unimplemented!()
}
}
@@ -803,7 +801,7 @@ mod tests {
}
impl Future for DelayedSourceCodeFuture {
- type Output = Result<ModuleSource, AnyError>;
+ type Output = Result<ModuleSource, Error>;
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
let inner = self.get_mut();
@@ -834,7 +832,7 @@ mod tests {
specifier: &str,
referrer: &str,
_is_root: bool,
- ) -> Result<ModuleSpecifier, AnyError> {
+ ) -> Result<ModuleSpecifier, Error> {
let referrer = if referrer == "." {
"file:///"
} else {
@@ -978,7 +976,7 @@ mod tests {
specifier: &str,
referrer: &str,
_is_main: bool,
- ) -> Result<ModuleSpecifier, AnyError> {
+ ) -> Result<ModuleSpecifier, Error> {
self.count.fetch_add(1, Ordering::Relaxed);
assert_eq!(specifier, "./b.js");
assert_eq!(referrer, "file:///a.js");
@@ -1096,7 +1094,7 @@ mod tests {
specifier: &str,
referrer: &str,
_is_main: bool,
- ) -> Result<ModuleSpecifier, AnyError> {
+ ) -> Result<ModuleSpecifier, Error> {
self.count.fetch_add(1, Ordering::Relaxed);
assert_eq!(specifier, "/foo.js");
assert_eq!(referrer, "file:///dyn_import2.js");
@@ -1156,7 +1154,7 @@ mod tests {
specifier: &str,
referrer: &str,
_is_main: bool,
- ) -> Result<ModuleSpecifier, AnyError> {
+ ) -> Result<ModuleSpecifier, Error> {
let c = self.resolve_count.fetch_add(1, Ordering::Relaxed);
assert!(c < 7);
assert_eq!(specifier, "./b.js");
@@ -1187,7 +1185,7 @@ mod tests {
_module_specifier: &ModuleSpecifier,
_maybe_referrer: Option<String>,
_is_dyn_import: bool,
- ) -> Pin<Box<dyn Future<Output = Result<(), AnyError>>>> {
+ ) -> Pin<Box<dyn Future<Output = Result<(), Error>>>> {
self.prepare_load_count.fetch_add(1, Ordering::Relaxed);
async { Ok(()) }.boxed_local()
}
@@ -1292,7 +1290,7 @@ mod tests {
specifier: &str,
referrer: &str,
_is_main: bool,
- ) -> Result<ModuleSpecifier, AnyError> {
+ ) -> Result<ModuleSpecifier, Error> {
self.resolve_count.fetch_add(1, Ordering::Relaxed);
let s = crate::resolve_import(specifier, referrer).unwrap();
Ok(s)
@@ -1634,7 +1632,7 @@ mod tests {
specifier: &str,
referrer: &str,
_is_main: bool,
- ) -> Result<ModuleSpecifier, AnyError> {
+ ) -> Result<ModuleSpecifier, Error> {
let s = crate::resolve_import(specifier, referrer).unwrap();
Ok(s)
}
diff --git a/core/ops.rs b/core/ops.rs
index f62fe7a8e..13f001146 100644
--- a/core/ops.rs
+++ b/core/ops.rs
@@ -1,11 +1,11 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
use crate::error::type_error;
-use crate::error::AnyError;
use crate::gotham_state::GothamState;
use crate::ops_metrics::OpsTracker;
use crate::resources::ResourceTable;
use crate::runtime::GetErrorClassFn;
+use anyhow::Error;
use futures::future::maybe_done;
use futures::future::FusedFuture;
use futures::future::MaybeDone;
@@ -96,13 +96,13 @@ pub struct OpPayload<'a, 'b, 'c> {
impl<'a, 'b, 'c> OpPayload<'a, 'b, 'c> {
pub fn deserialize<T: DeserializeOwned, U: DeserializeOwned>(
self,
- ) -> Result<(T, U), AnyError> {
+ ) -> Result<(T, U), Error> {
let a: T = serde_v8::from_v8(self.scope, self.a)
- .map_err(AnyError::from)
+ .map_err(Error::from)
.map_err(|e| type_error(format!("Error parsing args: {}", e)))?;
let b: U = serde_v8::from_v8(self.scope, self.b)
- .map_err(AnyError::from)
+ .map_err(Error::from)
.map_err(|e| type_error(format!("Error parsing args: {}", e)))?;
Ok((a, b))
}
@@ -144,7 +144,7 @@ pub struct OpError {
}
pub fn serialize_op_result<R: Serialize + 'static>(
- result: Result<R, AnyError>,
+ result: Result<R, Error>,
state: Rc<RefCell<OpState>>,
) -> OpResult {
match result {
diff --git a/core/ops_builtin.rs b/core/ops_builtin.rs
index a6cf82fe9..d759bc5ba 100644
--- a/core/ops_builtin.rs
+++ b/core/ops_builtin.rs
@@ -1,5 +1,4 @@
use crate::error::type_error;
-use crate::error::AnyError;
use crate::include_js_files;
use crate::op_async;
use crate::op_sync;
@@ -11,6 +10,7 @@ use crate::Extension;
use crate::OpState;
use crate::Resource;
use crate::ZeroCopyBuf;
+use anyhow::Error;
use std::cell::RefCell;
use std::io::{stderr, stdout, Write};
use std::rc::Rc;
@@ -51,7 +51,7 @@ pub fn op_resources(
state: &mut OpState,
_: (),
_: (),
-) -> Result<Vec<(ResourceId, String)>, AnyError> {
+) -> Result<Vec<(ResourceId, String)>, Error> {
let serialized_resources = state
.resource_table
.names()
@@ -65,7 +65,7 @@ pub fn op_close(
state: &mut OpState,
rid: Option<ResourceId>,
_: (),
-) -> Result<(), AnyError> {
+) -> Result<(), Error> {
// TODO(@AaronO): drop Option after improving type-strictness balance in
// serde_v8
let rid = rid.ok_or_else(|| type_error("missing or invalid `rid`"))?;
@@ -79,7 +79,7 @@ pub fn op_try_close(
state: &mut OpState,
rid: Option<ResourceId>,
_: (),
-) -> Result<(), AnyError> {
+) -> Result<(), Error> {
// TODO(@AaronO): drop Option after improving type-strictness balance in
// serde_v8.
let rid = rid.ok_or_else(|| type_error("missing or invalid `rid`"))?;
@@ -92,7 +92,7 @@ pub fn op_print(
_state: &mut OpState,
msg: String,
is_err: bool,
-) -> Result<(), AnyError> {
+) -> Result<(), Error> {
if is_err {
stderr().write_all(msg.as_bytes())?;
stderr().flush().unwrap();
@@ -123,7 +123,7 @@ pub fn op_wasm_streaming_feed(
state: &mut OpState,
rid: ResourceId,
bytes: ZeroCopyBuf,
-) -> Result<(), AnyError> {
+) -> Result<(), Error> {
let wasm_streaming =
state.resource_table.get::<WasmStreamingResource>(rid)?;
@@ -137,7 +137,7 @@ pub fn op_wasm_streaming_abort(
state: &mut OpState,
rid: ResourceId,
exception: serde_v8::Value,
-) -> Result<(), AnyError> {
+) -> Result<(), Error> {
let wasm_streaming =
state.resource_table.take::<WasmStreamingResource>(rid)?;
@@ -157,7 +157,7 @@ pub fn op_wasm_streaming_set_url(
state: &mut OpState,
rid: ResourceId,
url: String,
-) -> Result<(), AnyError> {
+) -> Result<(), Error> {
let wasm_streaming =
state.resource_table.get::<WasmStreamingResource>(rid)?;
@@ -170,7 +170,7 @@ pub fn op_metrics(
state: &mut OpState,
_: (),
_: (),
-) -> Result<(OpMetrics, Vec<OpMetrics>), AnyError> {
+) -> Result<(OpMetrics, Vec<OpMetrics>), Error> {
let aggregate = state.tracker.aggregate();
let per_op = state.tracker.per_op();
Ok((aggregate, per_op))
@@ -180,7 +180,7 @@ async fn op_read(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
buf: ZeroCopyBuf,
-) -> Result<u32, AnyError> {
+) -> Result<u32, Error> {
let resource = state.borrow().resource_table.get_any(rid)?;
resource.read(buf).await.map(|n| n as u32)
}
@@ -189,7 +189,7 @@ async fn op_write(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
buf: ZeroCopyBuf,
-) -> Result<u32, AnyError> {
+) -> Result<u32, Error> {
let resource = state.borrow().resource_table.get_any(rid)?;
resource.write(buf).await.map(|n| n as u32)
}
@@ -198,7 +198,7 @@ async fn op_shutdown(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
_: (),
-) -> Result<(), AnyError> {
+) -> Result<(), Error> {
let resource = state.borrow().resource_table.get_any(rid)?;
resource.shutdown().await
}
diff --git a/core/ops_json.rs b/core/ops_json.rs
index a2eff40ef..b3153763e 100644
--- a/core/ops_json.rs
+++ b/core/ops_json.rs
@@ -1,11 +1,11 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
-use crate::error::AnyError;
use crate::ops::OpCall;
use crate::serialize_op_result;
use crate::Op;
use crate::OpFn;
use crate::OpState;
+use anyhow::Error;
use serde::de::DeserializeOwned;
use serde::Serialize;
use std::cell::RefCell;
@@ -51,7 +51,7 @@ pub fn void_op_async() -> Box<OpFn> {
/// A more complete example is available in the examples directory.
pub fn op_sync<F, A, B, R>(op_fn: F) -> Box<OpFn>
where
- F: Fn(&mut OpState, A, B) -> Result<R, AnyError> + 'static,
+ F: Fn(&mut OpState, A, B) -> Result<R, Error> + 'static,
A: DeserializeOwned,
B: DeserializeOwned,
R: Serialize + 'static,
@@ -96,7 +96,7 @@ where
F: Fn(Rc<RefCell<OpState>>, A, B) -> R + 'static,
A: DeserializeOwned,
B: DeserializeOwned,
- R: Future<Output = Result<RV, AnyError>> + 'static,
+ R: Future<Output = Result<RV, Error>> + 'static,
RV: Serialize + 'static,
{
Box::new(move |state, payload| -> Op {
@@ -106,7 +106,7 @@ where
let args = match payload.deserialize() {
Ok(args) => args,
Err(err) => {
- return Op::Sync(serialize_op_result(Err::<(), AnyError>(err), state))
+ return Op::Sync(serialize_op_result(Err::<(), Error>(err), state))
}
};
let (a, b) = args;
@@ -128,7 +128,7 @@ where
F: Fn(Rc<RefCell<OpState>>, A, B) -> R + 'static,
A: DeserializeOwned,
B: DeserializeOwned,
- R: Future<Output = Result<RV, AnyError>> + 'static,
+ R: Future<Output = Result<RV, Error>> + 'static,
RV: Serialize + 'static,
{
Box::new(move |state, payload| -> Op {
@@ -138,7 +138,7 @@ where
let args = match payload.deserialize() {
Ok(args) => args,
Err(err) => {
- return Op::Sync(serialize_op_result(Err::<(), AnyError>(err), state))
+ return Op::Sync(serialize_op_result(Err::<(), Error>(err), state))
}
};
let (a, b) = args;
@@ -162,7 +162,7 @@ mod tests {
_state: Rc<RefCell<OpState>>,
msg: Option<String>,
_: (),
- ) -> Result<(), AnyError> {
+ ) -> Result<(), Error> {
assert_eq!(msg.unwrap(), "hello");
Err(crate::error::generic_error("foo"))
}
diff --git a/core/resources.rs b/core/resources.rs
index 33cabcad4..e1b923fd0 100644
--- a/core/resources.rs
+++ b/core/resources.rs
@@ -8,8 +8,8 @@
use crate::error::bad_resource_id;
use crate::error::not_supported;
-use crate::error::AnyError;
use crate::ZeroCopyBuf;
+use anyhow::Error;
use futures::Future;
use std::any::type_name;
use std::any::Any;
@@ -21,7 +21,7 @@ use std::pin::Pin;
use std::rc::Rc;
/// Returned by resource read/write/shutdown methods
-pub type AsyncResult<T> = Pin<Box<dyn Future<Output = Result<T, AnyError>>>>;
+pub type AsyncResult<T> = Pin<Box<dyn Future<Output = Result<T, Error>>>>;
/// All objects that can be store in the resource table should implement the
/// `Resource` trait.
@@ -130,7 +130,7 @@ impl ResourceTable {
/// Returns a reference counted pointer to the resource of type `T` with the
/// given `rid`. If `rid` is not present or has a type different than `T`,
/// this function returns `None`.
- pub fn get<T: Resource>(&self, rid: ResourceId) -> Result<Rc<T>, AnyError> {
+ pub fn get<T: Resource>(&self, rid: ResourceId) -> Result<Rc<T>, Error> {
self
.index
.get(&rid)
@@ -139,7 +139,7 @@ impl ResourceTable {
.ok_or_else(bad_resource_id)
}
- pub fn get_any(&self, rid: ResourceId) -> Result<Rc<dyn Resource>, AnyError> {
+ pub fn get_any(&self, rid: ResourceId) -> Result<Rc<dyn Resource>, Error> {
self
.index
.get(&rid)
@@ -151,10 +151,7 @@ impl ResourceTable {
/// If a resource with the given `rid` exists but its type does not match `T`,
/// it is not removed from the resource table. Note that the resource's
/// `close()` method is *not* called.
- pub fn take<T: Resource>(
- &mut self,
- rid: ResourceId,
- ) -> Result<Rc<T>, AnyError> {
+ pub fn take<T: Resource>(&mut self, rid: ResourceId) -> Result<Rc<T>, Error> {
let resource = self.get::<T>(rid)?;
self.index.remove(&rid);
Ok(resource)
@@ -165,7 +162,7 @@ impl ResourceTable {
pub fn take_any(
&mut self,
rid: ResourceId,
- ) -> Result<Rc<dyn Resource>, AnyError> {
+ ) -> Result<Rc<dyn Resource>, Error> {
self.index.remove(&rid).ok_or_else(bad_resource_id)
}
@@ -175,7 +172,7 @@ impl ResourceTable {
/// counted, therefore pending ops are not automatically cancelled. A resource
/// may implement the `close()` method to perform clean-ups such as canceling
/// ops.
- pub fn close(&mut self, rid: ResourceId) -> Result<(), AnyError> {
+ pub fn close(&mut self, rid: ResourceId) -> Result<(), Error> {
self
.index
.remove(&rid)
diff --git a/core/runtime.rs b/core/runtime.rs
index 704be7a76..c7831f88f 100644
--- a/core/runtime.rs
+++ b/core/runtime.rs
@@ -3,7 +3,6 @@
use crate::bindings;
use crate::error::attach_handle_to_error;
use crate::error::generic_error;
-use crate::error::AnyError;
use crate::error::ErrWithV8Handle;
use crate::error::JsError;
use crate::inspector::JsRuntimeInspector;
@@ -20,6 +19,7 @@ use crate::OpPayload;
use crate::OpResult;
use crate::OpState;
use crate::PromiseId;
+use anyhow::Error;
use futures::channel::oneshot;
use futures::future::poll_fn;
use futures::future::FutureExt;
@@ -47,10 +47,9 @@ pub enum Snapshot {
Boxed(Box<[u8]>),
}
-pub type JsErrorCreateFn = dyn Fn(JsError) -> AnyError;
+pub type JsErrorCreateFn = dyn Fn(JsError) -> Error;
-pub type GetErrorClassFn =
- &'static dyn for<'e> Fn(&'e AnyError) -> &'static str;
+pub type GetErrorClassFn = &'static dyn for<'e> Fn(&'e Error) -> &'static str;
/// Objects that need to live as long as the isolate
#[derive(Default)]
@@ -91,7 +90,7 @@ struct DynImportModEvaluate {
struct ModEvaluate {
promise: v8::Global<v8::Promise>,
- sender: oneshot::Sender<Result<(), AnyError>>,
+ sender: oneshot::Sender<Result<(), Error>>,
}
pub struct CrossIsolateStore<T>(Arc<Mutex<CrossIsolateStoreInner<T>>>);
@@ -450,7 +449,7 @@ impl JsRuntime {
}
/// Initializes JS of provided Extensions
- fn init_extension_js(&mut self) -> Result<(), AnyError> {
+ fn init_extension_js(&mut self) -> Result<(), Error> {
// Take extensions to avoid double-borrow
let mut extensions: Vec<Extension> = std::mem::take(&mut self.extensions);
for m in extensions.iter_mut() {
@@ -468,7 +467,7 @@ impl JsRuntime {
}
/// Initializes ops of provided Extensions
- fn init_extension_ops(&mut self) -> Result<(), AnyError> {
+ fn init_extension_ops(&mut self) -> Result<(), Error> {
let op_state = self.op_state();
// Take extensions to avoid double-borrow
let mut extensions: Vec<Extension> = std::mem::take(&mut self.extensions);
@@ -552,14 +551,14 @@ impl JsRuntime {
///
/// The same `name` value can be used for multiple executions.
///
- /// `AnyError` can be downcast to a type that exposes additional information
+ /// `Error` can be downcast to a type that exposes additional information
/// about the V8 exception. By default this type is `JsError`, however it may
/// be a different type if `RuntimeOptions::js_error_create_fn` has been set.
pub fn execute_script(
&mut self,
name: &str,
source_code: &str,
- ) -> Result<v8::Global<v8::Value>, AnyError> {
+ ) -> Result<v8::Global<v8::Value>, Error> {
let scope = &mut self.handle_scope();
let source = v8::String::new(scope, source_code).unwrap();
@@ -592,7 +591,7 @@ impl JsRuntime {
/// Takes a snapshot. The isolate should have been created with will_snapshot
/// set to true.
///
- /// `AnyError` can be downcast to a type that exposes additional information
+ /// `Error` can be downcast to a type that exposes additional information
/// about the V8 exception. By default this type is `JsError`, however it may
/// be a different type if `RuntimeOptions::js_error_create_fn` has been set.
pub fn snapshot(&mut self) -> v8::StartupData {
@@ -702,7 +701,7 @@ impl JsRuntime {
pub async fn resolve_value(
&mut self,
global: v8::Global<v8::Value>,
- ) -> Result<v8::Global<v8::Value>, AnyError> {
+ ) -> Result<v8::Global<v8::Value>, Error> {
poll_fn(|cx| {
let state = self.poll_event_loop(cx, false);
@@ -746,7 +745,7 @@ impl JsRuntime {
pub async fn run_event_loop(
&mut self,
wait_for_inspector: bool,
- ) -> Result<(), AnyError> {
+ ) -> Result<(), Error> {
poll_fn(|cx| self.poll_event_loop(cx, wait_for_inspector)).await
}
@@ -758,7 +757,7 @@ impl JsRuntime {
&mut self,
cx: &mut Context,
wait_for_inspector: bool,
- ) -> Poll<Result<(), AnyError>> {
+ ) -> Poll<Result<(), Error>> {
// We always poll the inspector first
let _ = self.inspector().poll_unpin(cx);
@@ -902,7 +901,7 @@ pub(crate) fn exception_to_err_result<'s, T>(
scope: &mut v8::HandleScope<'s>,
exception: v8::Local<v8::Value>,
in_promise: bool,
-) -> Result<T, AnyError> {
+) -> Result<T, Error> {
let is_terminating_exception = scope.is_execution_terminating();
let mut exception = exception;
@@ -943,7 +942,7 @@ impl JsRuntime {
pub(crate) fn instantiate_module(
&mut self,
id: ModuleId,
- ) -> Result<(), AnyError> {
+ ) -> Result<(), Error> {
let module_map_rc = Self::module_map(self.v8_isolate());
let scope = &mut self.handle_scope();
let tc_scope = &mut v8::TryCatch::new(scope);
@@ -981,7 +980,7 @@ impl JsRuntime {
&mut self,
load_id: ModuleLoadId,
id: ModuleId,
- ) -> Result<(), AnyError> {
+ ) -> Result<(), Error> {
let state_rc = Self::state(self.v8_isolate());
let module_map_rc = Self::module_map(self.v8_isolate());
@@ -1058,7 +1057,7 @@ impl JsRuntime {
/// Implementors must manually call `run_event_loop()` to drive module
/// evaluation future.
///
- /// `AnyError` can be downcast to a type that exposes additional information
+ /// `Error` can be downcast to a type that exposes additional information
/// about the V8 exception. By default this type is `JsError`, however it may
/// be a different type if `RuntimeOptions::js_error_create_fn` has been set.
///
@@ -1066,7 +1065,7 @@ impl JsRuntime {
pub fn mod_evaluate(
&mut self,
id: ModuleId,
- ) -> oneshot::Receiver<Result<(), AnyError>> {
+ ) -> oneshot::Receiver<Result<(), Error>> {
let state_rc = Self::state(self.v8_isolate());
let module_map_rc = Self::module_map(self.v8_isolate());
let scope = &mut self.handle_scope();
@@ -1130,7 +1129,7 @@ impl JsRuntime {
receiver
}
- fn dynamic_import_reject(&mut self, id: ModuleLoadId, err: AnyError) {
+ fn dynamic_import_reject(&mut self, id: ModuleLoadId, err: Error) {
let module_map_rc = Self::module_map(self.v8_isolate());
let scope = &mut self.handle_scope();
@@ -1193,7 +1192,7 @@ impl JsRuntime {
fn prepare_dyn_imports(
&mut self,
cx: &mut Context,
- ) -> Poll<Result<(), AnyError>> {
+ ) -> Poll<Result<(), Error>> {
let module_map_rc = Self::module_map(self.v8_isolate());
if module_map_rc.borrow().preparing_dynamic_imports.is_empty() {
@@ -1230,10 +1229,7 @@ impl JsRuntime {
}
}
- fn poll_dyn_imports(
- &mut self,
- cx: &mut Context,
- ) -> Poll<Result<(), AnyError>> {
+ fn poll_dyn_imports(&mut self, cx: &mut Context) -> Poll<Result<(), Error>> {
let module_map_rc = Self::module_map(self.v8_isolate());
if module_map_rc.borrow().pending_dynamic_imports.is_empty() {
@@ -1408,7 +1404,7 @@ impl JsRuntime {
&mut self,
specifier: &ModuleSpecifier,
code: Option<String>,
- ) -> Result<ModuleId, AnyError> {
+ ) -> Result<ModuleId, Error> {
let module_map_rc = Self::module_map(self.v8_isolate());
if let Some(code) = code {
module_map_rc.borrow_mut().new_module(
@@ -1445,7 +1441,7 @@ impl JsRuntime {
&mut self,
specifier: &ModuleSpecifier,
code: Option<String>,
- ) -> Result<ModuleId, AnyError> {
+ ) -> Result<ModuleId, Error> {
let module_map_rc = Self::module_map(self.v8_isolate());
if let Some(code) = code {
module_map_rc.borrow_mut().new_module(
@@ -1471,7 +1467,7 @@ impl JsRuntime {
Ok(root_id)
}
- fn check_promise_exceptions(&mut self) -> Result<(), AnyError> {
+ fn check_promise_exceptions(&mut self) -> Result<(), Error> {
let state_rc = Self::state(self.v8_isolate());
let mut state = state_rc.borrow_mut();
@@ -1496,7 +1492,7 @@ impl JsRuntime {
}
// Send finished responses to JS
- fn resolve_async_ops(&mut self, cx: &mut Context) -> Result<(), AnyError> {
+ fn resolve_async_ops(&mut self, cx: &mut Context) -> Result<(), Error> {
let state_rc = Self::state(self.v8_isolate());
let js_recv_cb_handle = state_rc.borrow().js_recv_cb.clone().unwrap();
@@ -1552,7 +1548,7 @@ impl JsRuntime {
}
}
- fn drain_macrotasks(&mut self) -> Result<(), AnyError> {
+ fn drain_macrotasks(&mut self) -> Result<(), Error> {
let js_macrotask_cb_handle =
match &Self::state(self.v8_isolate()).borrow().js_macrotask_cb {
Some(handle) => handle.clone(),
@@ -1909,11 +1905,11 @@ pub mod tests {
#[test]
fn test_error_builder() {
- fn op_err(_: &mut OpState, _: (), _: ()) -> Result<(), AnyError> {
+ fn op_err(_: &mut OpState, _: (), _: ()) -> Result<(), Error> {
Err(custom_error("DOMExceptionOperationError", "abc"))
}
- pub fn get_error_class_name(_: &AnyError) -> &'static str {
+ pub fn get_error_class_name(_: &Error) -> &'static str {
"DOMExceptionOperationError"
}
@@ -2077,7 +2073,7 @@ pub mod tests {
specifier: &str,
referrer: &str,
_is_main: bool,
- ) -> Result<ModuleSpecifier, AnyError> {
+ ) -> Result<ModuleSpecifier, Error> {
assert_eq!(specifier, "file:///main.js");
assert_eq!(referrer, ".");
let s = crate::resolve_import(specifier, referrer).unwrap();
@@ -2316,7 +2312,7 @@ assertEquals(1, notify_return_value);
op_state: Rc<RefCell<OpState>>,
_: (),
_: (),
- ) -> Result<(), AnyError> {
+ ) -> Result<(), Error> {
let n = {
let op_state = op_state.borrow();
let inner_state = op_state.borrow::<InnerState>();
diff --git a/ext/tls/lib.rs b/ext/tls/lib.rs
index fb4fac85b..b29a142b9 100644
--- a/ext/tls/lib.rs
+++ b/ext/tls/lib.rs
@@ -6,7 +6,7 @@ pub use rustls_native_certs;
pub use webpki;
pub use webpki_roots;
-use deno_core::error::anyhow;
+use deno_core::anyhow::anyhow;
use deno_core::error::custom_error;
use deno_core::error::generic_error;
use deno_core::error::AnyError;
diff --git a/runtime/fs_util.rs b/runtime/fs_util.rs
index 93286ecf3..695b3be62 100644
--- a/runtime/fs_util.rs
+++ b/runtime/fs_util.rs
@@ -1,7 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
+use deno_core::anyhow::Context;
use deno_core::error::AnyError;
-use deno_core::error::Context;
pub use deno_core::normalize_path;
use std::env::current_dir;
use std::io::Error;
diff --git a/runtime/ops/runtime.rs b/runtime/ops/runtime.rs
index 66dd0de4b..6006716ef 100644
--- a/runtime/ops/runtime.rs
+++ b/runtime/ops/runtime.rs
@@ -1,8 +1,8 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
use crate::permissions::Permissions;
+use deno_core::anyhow::Context;
use deno_core::error::AnyError;
-use deno_core::error::Context;
use deno_core::op_sync;
use deno_core::Extension;
use deno_core::ModuleSpecifier;