From 63b8089bda8c88413bfad24aef415abc09e8d5c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20D=C3=BCrr?= <102963075+cd-work@users.noreply.github.com> Date: Fri, 2 Sep 2022 20:53:23 +0000 Subject: [PATCH] refactor: move JsError formatting to deno_runtime (#15345) This takes the existing `fmt_error` module from cli and puts it as a public module into `deno_runtime`. --- cli/file_watcher.rs | 2 +- cli/main.rs | 3 +-- cli/standalone.rs | 2 +- cli/tools/lint.rs | 4 ++-- cli/tools/test.rs | 2 +- cli/worker.rs | 2 +- {cli => runtime}/fmt_errors.rs | 1 + runtime/lib.rs | 1 + 8 files changed, 9 insertions(+), 8 deletions(-) rename {cli => runtime}/fmt_errors.rs (99%) diff --git a/cli/file_watcher.rs b/cli/file_watcher.rs index c5a92e5bfa..6c8a142a61 100644 --- a/cli/file_watcher.rs +++ b/cli/file_watcher.rs @@ -1,12 +1,12 @@ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::colors; -use crate::fmt_errors::format_js_error; use crate::fs_util::canonicalize_path; use deno_core::error::AnyError; use deno_core::error::JsError; use deno_core::futures::Future; +use deno_runtime::fmt_errors::format_js_error; use log::info; use notify::event::Event as NotifyEvent; use notify::event::EventKind; diff --git a/cli/main.rs b/cli/main.rs index 0c4b5c8935..bffe9c4703 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -15,7 +15,6 @@ mod emit; mod errors; mod file_fetcher; mod file_watcher; -mod fmt_errors; mod fs_util; mod graph_util; mod http_cache; @@ -67,7 +66,6 @@ use crate::cache::TypeCheckCache; use crate::emit::TsConfigType; use crate::file_fetcher::File; use crate::file_watcher::ResolutionResult; -use crate::fmt_errors::format_js_error; use crate::graph_util::graph_lock_or_exit; use crate::graph_util::graph_valid; use crate::proc_state::ProcState; @@ -89,6 +87,7 @@ use deno_core::serde_json::json; use deno_core::v8_set_flags; use deno_core::ModuleSpecifier; use deno_runtime::colors; +use deno_runtime::fmt_errors::format_js_error; use deno_runtime::permissions::Permissions; use deno_runtime::tokio_util::run_local; use log::debug; diff --git a/cli/standalone.rs b/cli/standalone.rs index 147a1a57e7..fa5fffd13b 100644 --- a/cli/standalone.rs +++ b/cli/standalone.rs @@ -3,7 +3,6 @@ use crate::args::Flags; use crate::colors; use crate::file_fetcher::get_source_from_data_url; -use crate::fmt_errors::format_js_error; use crate::ops; use crate::proc_state::ProcState; use crate::version; @@ -25,6 +24,7 @@ use deno_graph::source::Resolver; use deno_runtime::deno_broadcast_channel::InMemoryBroadcastChannel; use deno_runtime::deno_tls::rustls_pemfile; use deno_runtime::deno_web::BlobStore; +use deno_runtime::fmt_errors::format_js_error; use deno_runtime::permissions::Permissions; use deno_runtime::permissions::PermissionsOptions; use deno_runtime::worker::MainWorker; diff --git a/cli/tools/lint.rs b/cli/tools/lint.rs index cfc6633875..0bee44d4c0 100644 --- a/cli/tools/lint.rs +++ b/cli/tools/lint.rs @@ -12,7 +12,6 @@ use crate::args::LintFlags; use crate::colors; use crate::file_watcher; use crate::file_watcher::ResolutionResult; -use crate::fmt_errors; use crate::fs_util::collect_files; use crate::fs_util::is_supported_ext; use crate::fs_util::specifier_to_file_path; @@ -29,6 +28,7 @@ use deno_lint::linter::Linter; use deno_lint::linter::LinterBuilder; use deno_lint::rules; use deno_lint::rules::LintRule; +use deno_runtime::fmt_errors::format_location; use log::debug; use log::info; use serde::Serialize; @@ -382,7 +382,7 @@ impl LintReporter for PrettyLintReporter { &source_lines, d.range.clone(), d.hint.as_ref(), - &fmt_errors::format_location(&JsStackFrame::from_location( + &format_location(&JsStackFrame::from_location( Some(d.filename.clone()), Some(d.range.start.line_index as i64 + 1), // 1-indexed // todo(#11111): make 1-indexed as well diff --git a/cli/tools/test.rs b/cli/tools/test.rs index 265b39b57a..cb5b41042e 100644 --- a/cli/tools/test.rs +++ b/cli/tools/test.rs @@ -10,7 +10,6 @@ use crate::display; use crate::file_fetcher::File; use crate::file_watcher; use crate::file_watcher::ResolutionResult; -use crate::fmt_errors::format_js_error; use crate::fs_util::collect_specifiers; use crate::fs_util::is_supported_test_ext; use crate::fs_util::is_supported_test_path; @@ -34,6 +33,7 @@ use deno_core::parking_lot::Mutex; use deno_core::url::Url; use deno_core::ModuleSpecifier; use deno_graph::ModuleKind; +use deno_runtime::fmt_errors::format_js_error; use deno_runtime::ops::io::Stdio; use deno_runtime::ops::io::StdioPipe; use deno_runtime::permissions::Permissions; diff --git a/cli/worker.rs b/cli/worker.rs index 1c4c6475a3..d366398217 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -11,6 +11,7 @@ use deno_core::Extension; use deno_core::ModuleId; use deno_graph::source::ResolveResponse; use deno_runtime::colors; +use deno_runtime::fmt_errors::format_js_error; use deno_runtime::ops::worker_host::CreateWebWorkerCb; use deno_runtime::ops::worker_host::WorkerEventCb; use deno_runtime::permissions::Permissions; @@ -24,7 +25,6 @@ use crate::args::DenoSubcommand; use crate::checksum; use crate::compat; use crate::errors; -use crate::fmt_errors::format_js_error; use crate::module_loader::CliModuleLoader; use crate::node; use crate::npm::NpmPackageReference; diff --git a/cli/fmt_errors.rs b/runtime/fmt_errors.rs similarity index 99% rename from cli/fmt_errors.rs rename to runtime/fmt_errors.rs index 53cf975bc3..aa1f60450e 100644 --- a/cli/fmt_errors.rs +++ b/runtime/fmt_errors.rs @@ -189,6 +189,7 @@ fn format_js_error_inner(js_error: &JsError, is_child: bool) -> String { s } +/// Format a [`JsError`] for terminal output. pub fn format_js_error(js_error: &JsError) -> String { format_js_error_inner(js_error, false) } diff --git a/runtime/lib.rs b/runtime/lib.rs index dfbfaafaa4..6566623913 100644 --- a/runtime/lib.rs +++ b/runtime/lib.rs @@ -19,6 +19,7 @@ pub use deno_webstorage; pub mod colors; pub mod errors; +pub mod fmt_errors; pub mod fs_util; pub mod inspector_server; pub mod js;