From b2036a4db71afd67a78f932528143fb07faea538 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Tue, 16 Nov 2021 09:02:28 -0500 Subject: [PATCH] refactor: re-export anyhow from deno_core (#12777) --- cli/ast/mod.rs | 2 +- cli/config_file.rs | 4 +- cli/emit.rs | 4 +- cli/fs_util.rs | 2 +- cli/lsp/analysis.rs | 2 +- cli/lsp/cache.rs | 2 +- cli/lsp/config.rs | 2 +- cli/lsp/diagnostics.rs | 2 +- cli/lsp/language_server.rs | 2 +- cli/lsp/path_to_regex.rs | 2 +- cli/lsp/registries.rs | 4 +- cli/lsp/tsc.rs | 2 +- cli/ops/runtime_compiler.rs | 2 +- cli/proc_state.rs | 4 +- cli/standalone.rs | 4 +- cli/tools/lint.rs | 5 ++- cli/tools/standalone.rs | 2 +- cli/tools/upgrade.rs | 2 +- cli/tsc.rs | 4 +- core/async_cancel.rs | 4 +- core/bindings.rs | 8 ++-- core/error.rs | 48 +++++++++++---------- core/error_codes.rs | 4 +- core/examples/http_bench_json_ops.rs | 26 ++++-------- core/extensions.rs | 13 +++--- core/inspector.rs | 4 +- core/lib.rs | 1 + core/modules.rs | 50 +++++++++++----------- core/ops.rs | 10 ++--- core/ops_builtin.rs | 24 +++++------ core/ops_json.rs | 14 +++---- core/resources.rs | 17 ++++---- core/runtime.rs | 62 +++++++++++++--------------- ext/tls/lib.rs | 2 +- runtime/fs_util.rs | 2 +- runtime/ops/runtime.rs | 2 +- 36 files changed, 165 insertions(+), 179 deletions(-) diff --git a/cli/ast/mod.rs b/cli/ast/mod.rs index a6cd865525..ac3dd58870 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 20e254dd0d..d61eb23468 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 a189b8202a..9eac892fff 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 21a9a6aadc..0602994e3b 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 011ffa7574..18d6751094 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 b7bdb90c59..2471284201 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 af2caf22aa..27efaf4970 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 f14d80cd83..f84d22b45c 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 10a69fadbb..dbe00861eb 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 6e0ed33902..ce935ee27b 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 bef55150de..c8ab5d5867 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 9350d6f195..b5ce48fab4 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 b16fbcf694..145da4c1d6 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 7a42b62198..8a3864d398 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 e0190920f2..92e7dfbae0 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 4a1f25dd42..ec42adc34e 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 fb07254aaf..5dd6f23ad2 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 6de8ba9321..5838cb2900 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 5f5c09539c..184fbd144b 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 e3110bf135..ab7ec22483 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 10daee27ab..63c7ea4b96 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::::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::::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::::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 793a42603f..e8c0305d48 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>, -) -> AnyError { +) -> Error { CustomError { class, message: message.into(), @@ -25,39 +23,39 @@ pub fn custom_error( .into() } -pub fn generic_error(message: impl Into>) -> AnyError { +pub fn generic_error(message: impl Into>) -> Error { custom_error("Error", message) } -pub fn type_error(message: impl Into>) -> AnyError { +pub fn type_error(message: impl Into>) -> Error { custom_error("TypeError", message) } -pub fn range_error(message: impl Into>) -> AnyError { +pub fn range_error(message: impl Into>) -> 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>) -> AnyError { +pub fn uri_error(message: impl Into>) -> Error { custom_error("URIError", message) } -pub fn bad_resource(message: impl Into>) -> AnyError { +pub fn bad_resource(message: impl Into>) -> 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::().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, -) -> 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. pub(crate) struct ErrWithV8Handle { - err: AnyError, + err: Error, handle: v8::Global, } impl ErrWithV8Handle { pub fn new( scope: &mut v8::Isolate, - err: AnyError, + err: Error, handle: v8::Local, ) -> 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 { - ::fmt(&self.err, f) + ::fmt(&self.err, f) } } diff --git a/core/error_codes.rs b/core/error_codes.rs index fc613426fd..43a6c43919 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::() .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 6f14f558cb..641483b0b1 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) -> Result { + async fn accept(self: Rc) -> Result { 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 for TcpListener { - type Error = Error; + type Error = std::io::Error; fn try_from( std_listener: std::net::TcpListener, ) -> Result { @@ -78,21 +77,18 @@ struct TcpStream { } impl TcpStream { - async fn read( - self: Rc, - mut buf: ZeroCopyBuf, - ) -> Result { + async fn read(self: Rc, mut buf: ZeroCopyBuf) -> Result { 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, buf: ZeroCopyBuf) -> Result { + async fn write(self: Rc, buf: ZeroCopyBuf) -> Result { 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 { +fn op_listen(state: &mut OpState, _: (), _: ()) -> Result { log::debug!("listen"); let addr = "127.0.0.1:4544".parse::().unwrap(); let std_listener = std::net::TcpListener::bind(&addr)?; @@ -147,7 +139,7 @@ async fn op_accept( state: Rc>, rid: ResourceId, _: (), -) -> Result { +) -> Result { log::debug!("accept rid={}", rid); let listener = state.borrow().resource_table.get::(rid)?; diff --git a/core/extensions.rs b/core/extensions.rs index 54d6480711..587a2d0614 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); -pub type SourceLoadFn = dyn Fn() -> Result; +pub type SourceLoadFn = dyn Fn() -> Result; pub type OpPair = (&'static str, Box); pub type OpMiddlewareFn = dyn Fn(&'static str, Box) -> Box; -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(&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 3e84bcd584..8a686dc635 100644 --- a/core/inspector.rs +++ b/core/inspector.rs @@ -5,7 +5,6 @@ //! 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, - ) -> Result { + ) -> Result { let id = self.next_message_id; self.next_message_id += 1; diff --git a/core/lib.rs b/core/lib.rs index ceb2b89afe..87994720f4 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 dc2e5bb321..bc3885a7be 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)>; -pub type ModuleSourceFuture = - dyn Future>; + dyn Future)>; +pub type ModuleSourceFuture = dyn Future>; pub trait ModuleLoader { /// Returns an absolute URL. @@ -71,7 +70,7 @@ pub trait ModuleLoader { specifier: &str, referrer: &str, _is_main: bool, - ) -> Result; + ) -> Result; /// Given ModuleSpecifier, load its source code. /// @@ -99,7 +98,7 @@ pub trait ModuleLoader { _module_specifier: &ModuleSpecifier, _maybe_referrer: Option, _is_dyn_import: bool, - ) -> Pin>>> { + ) -> Pin>>> { async { Ok(()) }.boxed_local() } } @@ -114,7 +113,7 @@ impl ModuleLoader for NoopModuleLoader { _specifier: &str, _referrer: &str, _is_main: bool, - ) -> Result { + ) -> Result { Err(generic_error("Module loading is not supported")) } @@ -142,7 +141,7 @@ impl ModuleLoader for FsModuleLoader { specifier: &str, referrer: &str, _is_main: bool, - ) -> Result { + ) -> Result { Ok(crate::resolve_import(specifier, referrer)?) } @@ -257,7 +256,7 @@ impl RecursiveModuleLoad { load } - pub fn resolve_root(&self) -> Result { + pub fn resolve_root(&self) -> Result { 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; + type Item = Result; fn poll_next( self: Pin<&mut Self>, @@ -529,7 +528,7 @@ impl ModuleMap { main: bool, name: &str, source: &str, - ) -> Result { + ) -> Result { 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>, specifier: &str, - ) -> Result { + ) -> Result { 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>, specifier: &str, - ) -> Result { + ) -> Result { 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; + type Output = Result; fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll { let inner = self.get_mut(); @@ -834,7 +832,7 @@ mod tests { specifier: &str, referrer: &str, _is_root: bool, - ) -> Result { + ) -> Result { let referrer = if referrer == "." { "file:///" } else { @@ -978,7 +976,7 @@ mod tests { specifier: &str, referrer: &str, _is_main: bool, - ) -> Result { + ) -> Result { 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 { + ) -> Result { 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 { + ) -> Result { 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, _is_dyn_import: bool, - ) -> Pin>>> { + ) -> Pin>>> { 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 { + ) -> Result { 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 { + ) -> Result { let s = crate::resolve_import(specifier, referrer).unwrap(); Ok(s) } diff --git a/core/ops.rs b/core/ops.rs index f62fe7a8e6..13f0011461 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( 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( - result: Result, + result: Result, state: Rc>, ) -> OpResult { match result { diff --git a/core/ops_builtin.rs b/core/ops_builtin.rs index a6cf82fe96..d759bc5ba1 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, AnyError> { +) -> Result, Error> { let serialized_resources = state .resource_table .names() @@ -65,7 +65,7 @@ pub fn op_close( state: &mut OpState, rid: Option, _: (), -) -> 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, _: (), -) -> 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::(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::(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::(rid)?; @@ -170,7 +170,7 @@ pub fn op_metrics( state: &mut OpState, _: (), _: (), -) -> Result<(OpMetrics, Vec), AnyError> { +) -> Result<(OpMetrics, Vec), 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>, rid: ResourceId, buf: ZeroCopyBuf, -) -> Result { +) -> Result { 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>, rid: ResourceId, buf: ZeroCopyBuf, -) -> Result { +) -> Result { 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>, 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 a2eff40efa..b3153763e1 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 { /// A more complete example is available in the examples directory. pub fn op_sync(op_fn: F) -> Box where - F: Fn(&mut OpState, A, B) -> Result + 'static, + F: Fn(&mut OpState, A, B) -> Result + 'static, A: DeserializeOwned, B: DeserializeOwned, R: Serialize + 'static, @@ -96,7 +96,7 @@ where F: Fn(Rc>, A, B) -> R + 'static, A: DeserializeOwned, B: DeserializeOwned, - R: Future> + 'static, + R: Future> + '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>, A, B) -> R + 'static, A: DeserializeOwned, B: DeserializeOwned, - R: Future> + 'static, + R: Future> + '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>, msg: Option, _: (), - ) -> 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 33cabcad4d..e1b923fd03 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 = Pin>>>; +pub type AsyncResult = Pin>>>; /// 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(&self, rid: ResourceId) -> Result, AnyError> { + pub fn get(&self, rid: ResourceId) -> Result, 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, AnyError> { + pub fn get_any(&self, rid: ResourceId) -> Result, 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( - &mut self, - rid: ResourceId, - ) -> Result, AnyError> { + pub fn take(&mut self, rid: ResourceId) -> Result, Error> { let resource = self.get::(rid)?; self.index.remove(&rid); Ok(resource) @@ -165,7 +162,7 @@ impl ResourceTable { pub fn take_any( &mut self, rid: ResourceId, - ) -> Result, AnyError> { + ) -> Result, 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 704be7a769..c7831f88f8 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, - sender: oneshot::Sender>, + sender: oneshot::Sender>, } pub struct CrossIsolateStore(Arc>>); @@ -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 = 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 = 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, AnyError> { + ) -> Result, 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, - ) -> Result, AnyError> { + ) -> Result, 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> { + ) -> Poll> { // 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, in_promise: bool, -) -> Result { +) -> Result { 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> { + ) -> oneshot::Receiver> { 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> { + ) -> Poll> { 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> { + fn poll_dyn_imports(&mut self, cx: &mut Context) -> Poll> { 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, - ) -> Result { + ) -> Result { 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, - ) -> Result { + ) -> Result { 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 { + ) -> Result { 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>, _: (), _: (), - ) -> Result<(), AnyError> { + ) -> Result<(), Error> { let n = { let op_state = op_state.borrow(); let inner_state = op_state.borrow::(); diff --git a/ext/tls/lib.rs b/ext/tls/lib.rs index fb4fac85b6..b29a142b9a 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 93286ecf3f..695b3be62d 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 66dd0de4b8..6006716efa 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;