mirror of
https://github.com/denoland/deno.git
synced 2025-08-03 10:33:54 +00:00
refactor: use the 'anyhow' crate instead of 'ErrBox' (#7476)
This commit is contained in:
parent
3da20d19a1
commit
f5b40c918c
63 changed files with 898 additions and 861 deletions
|
@ -1,5 +1,8 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
//! This mod provides functions to remap a deno_core::deno_core::JsError based on a source map
|
||||
|
||||
//! This mod provides functions to remap a `JsError` based on a source map.
|
||||
|
||||
use deno_core::error::JsError as CoreJsError;
|
||||
use sourcemap::SourceMap;
|
||||
use std::collections::HashMap;
|
||||
use std::str;
|
||||
|
@ -18,13 +21,13 @@ pub trait SourceMapGetter {
|
|||
/// find a SourceMap.
|
||||
pub type CachedMaps = HashMap<String, Option<SourceMap>>;
|
||||
|
||||
/// Apply a source map to a deno_core::JsError, returning a JsError where file
|
||||
/// names and line/column numbers point to the location in the original source,
|
||||
/// rather than the transpiled source code.
|
||||
/// Apply a source map to a `deno_core::JsError`, returning a `JsError` where
|
||||
/// file names and line/column numbers point to the location in the original
|
||||
/// source, rather than the transpiled source code.
|
||||
pub fn apply_source_map<G: SourceMapGetter>(
|
||||
js_error: &deno_core::JsError,
|
||||
js_error: &CoreJsError,
|
||||
getter: &G,
|
||||
) -> deno_core::JsError {
|
||||
) -> CoreJsError {
|
||||
// Note that js_error.frames has already been source mapped in
|
||||
// prepareStackTrace().
|
||||
let mut mappings_map: CachedMaps = HashMap::new();
|
||||
|
@ -67,7 +70,7 @@ pub fn apply_source_map<G: SourceMapGetter>(
|
|||
_ => js_error.source_line.clone(),
|
||||
};
|
||||
|
||||
deno_core::JsError {
|
||||
CoreJsError {
|
||||
message: js_error.message.clone(),
|
||||
source_line,
|
||||
script_resource_name,
|
||||
|
@ -194,7 +197,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn apply_source_map_line() {
|
||||
let e = deno_core::JsError {
|
||||
let e = CoreJsError {
|
||||
message: "TypeError: baz".to_string(),
|
||||
source_line: Some("foo".to_string()),
|
||||
script_resource_name: Some("foo_bar.ts".to_string()),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue