Skip to content

Commit

Permalink
refactor: move JsError formatting to deno_runtime (#15345)
Browse files Browse the repository at this point in the history
This takes the existing `fmt_error` module from cli and puts it as a
public module into `deno_runtime`.
  • Loading branch information
cd-work authored Sep 2, 2022
1 parent 4f8dea1 commit 63b8089
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cli/file_watcher.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 1 addition & 2 deletions cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion cli/standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions cli/tools/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cli/tools/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion cli/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions cli/fmt_errors.rs → runtime/fmt_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions runtime/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 63b8089

Please sign in to comment.