mirror of
https://github.com/denoland/deno.git
synced 2025-03-04 01:44:26 -05:00
perf(cli/proc_state): Get error source lines from memory (#15031)
This commit is contained in:
parent
687c712be3
commit
989c723130
5 changed files with 15 additions and 33 deletions
|
@ -663,22 +663,22 @@ impl SourceMapGetter for ProcState {
|
||||||
file_name: &str,
|
file_name: &str,
|
||||||
line_number: usize,
|
line_number: usize,
|
||||||
) -> Option<String> {
|
) -> Option<String> {
|
||||||
if let Ok(specifier) = resolve_url(file_name) {
|
let graph_data = self.graph_data.read();
|
||||||
self.file_fetcher.get_source(&specifier).map(|out| {
|
let specifier = graph_data.follow_redirect(&resolve_url(file_name).ok()?);
|
||||||
// Do NOT use .lines(): it skips the terminating empty line.
|
let code = match graph_data.get(&specifier) {
|
||||||
// (due to internally using_terminator() instead of .split())
|
Some(ModuleEntry::Module { code, .. }) => code,
|
||||||
let lines: Vec<&str> = out.source.split('\n').collect();
|
_ => return None,
|
||||||
if line_number >= lines.len() {
|
};
|
||||||
format!(
|
// Do NOT use .lines(): it skips the terminating empty line.
|
||||||
"{} Couldn't format source line: Line {} is out of bounds (source may have changed at runtime)",
|
// (due to internally using_terminator() instead of .split())
|
||||||
crate::colors::yellow("Warning"), line_number + 1,
|
let lines: Vec<&str> = code.split('\n').collect();
|
||||||
)
|
if line_number >= lines.len() {
|
||||||
} else {
|
Some(format!(
|
||||||
lines[line_number].to_string()
|
"{} Couldn't format source line: Line {} is out of bounds (source may have changed at runtime)",
|
||||||
}
|
crate::colors::yellow("Warning"), line_number + 1,
|
||||||
})
|
))
|
||||||
} else {
|
} else {
|
||||||
None
|
Some(lines[line_number].to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2357,12 +2357,6 @@ itest!(long_data_url_formatting {
|
||||||
exit_code: 1,
|
exit_code: 1,
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(eval_context_throw_with_conflicting_source {
|
|
||||||
args: "run eval_context_throw_with_conflicting_source.ts",
|
|
||||||
output: "eval_context_throw_with_conflicting_source.ts.out",
|
|
||||||
exit_code: 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
itest!(eval_context_throw_dom_exception {
|
itest!(eval_context_throw_dom_exception {
|
||||||
args: "run eval_context_throw_dom_exception.js",
|
args: "run eval_context_throw_dom_exception.js",
|
||||||
output: "eval_context_throw_dom_exception.js.out",
|
output: "eval_context_throw_dom_exception.js.out",
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
throw new Error("foo");
|
|
|
@ -1,6 +0,0 @@
|
||||||
// deno-lint-ignore no-explicit-any
|
|
||||||
const [, errorInfo] = (Deno as any).core.evalContext(
|
|
||||||
'/* aaaaaaaaaaaaaaaaa */ throw new Error("foo")',
|
|
||||||
new URL("eval_context_conflicting_source.ts", import.meta.url).href,
|
|
||||||
);
|
|
||||||
throw errorInfo.thrown;
|
|
|
@ -1,5 +0,0 @@
|
||||||
[WILDCARD]error: Uncaught Error: foo
|
|
||||||
Warning Couldn't format source line: Column 31 is out of bounds (source may have changed at runtime)
|
|
||||||
at file:///[WILDCARD]/eval_context_conflicting_source.ts:1:31
|
|
||||||
at [WILDCARD]
|
|
||||||
at file:///[WILDCARD]/eval_context_throw_with_conflicting_source.ts:[WILDCARD]
|
|
Loading…
Add table
Reference in a new issue