mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 09:31:22 -05:00
refactor(cli): unify display of errors from Rust and JS (#5183)
This commit is contained in:
parent
670d01d012
commit
1fddcc3721
10 changed files with 25 additions and 23 deletions
|
@ -89,18 +89,16 @@ fn format_category_and_code(
|
|||
code: i64,
|
||||
) -> String {
|
||||
let category = match category {
|
||||
DiagnosticCategory::Error => {
|
||||
format!("{}", colors::red_bold("error".to_string()))
|
||||
}
|
||||
DiagnosticCategory::Warning => "warn".to_string(),
|
||||
DiagnosticCategory::Debug => "debug".to_string(),
|
||||
DiagnosticCategory::Info => "info".to_string(),
|
||||
DiagnosticCategory::Error => "ERROR".to_string(),
|
||||
DiagnosticCategory::Warning => "WARN".to_string(),
|
||||
DiagnosticCategory::Debug => "DEBUG".to_string(),
|
||||
DiagnosticCategory::Info => "INFO".to_string(),
|
||||
_ => "".to_string(),
|
||||
};
|
||||
|
||||
let code = colors::bold(format!("TS{}", code.to_string())).to_string();
|
||||
|
||||
format!("{} {}", category, code)
|
||||
format!("{} [{}]", code, category)
|
||||
}
|
||||
|
||||
fn format_message(
|
||||
|
@ -433,14 +431,14 @@ mod tests {
|
|||
#[test]
|
||||
fn diagnostic_to_string1() {
|
||||
let d = diagnostic1();
|
||||
let expected = "error TS2322: Type \'(o: T) => { v: any; f: (x: B) => string; }[]\' is not assignable to type \'(r: B) => Value<B>[]\'.\n Types of parameters \'o\' and \'r\' are incompatible.\n Type \'B\' is not assignable to type \'T\'.\n values: o => [\n ~~~~~~\n at deno/tests/complex_diagnostics.ts:19:3\n\n The expected type comes from property \'values\' which is declared here on type \'SettingsInterface<B>\'\n values?: (r: T) => Array<Value<T>>;\n ~~~~~~\n at deno/tests/complex_diagnostics.ts:7:3";
|
||||
let expected = "TS2322 [ERROR]: Type \'(o: T) => { v: any; f: (x: B) => string; }[]\' is not assignable to type \'(r: B) => Value<B>[]\'.\n Types of parameters \'o\' and \'r\' are incompatible.\n Type \'B\' is not assignable to type \'T\'.\n values: o => [\n ~~~~~~\n at deno/tests/complex_diagnostics.ts:19:3\n\n The expected type comes from property \'values\' which is declared here on type \'SettingsInterface<B>\'\n values?: (r: T) => Array<Value<T>>;\n ~~~~~~\n at deno/tests/complex_diagnostics.ts:7:3";
|
||||
assert_eq!(expected, strip_ansi_codes(&d.to_string()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn diagnostic_to_string2() {
|
||||
let d = diagnostic2();
|
||||
let expected = "error TS2322: Example 1\n values: o => [\n ~~~~~~\n at deno/tests/complex_diagnostics.ts:19:3\n\nerror TS2000: Example 2\n values: undefined,\n ~~~~~~\n at /foo/bar.ts:129:3\n\nFound 2 errors.";
|
||||
let expected = "TS2322 [ERROR]: Example 1\n values: o => [\n ~~~~~~\n at deno/tests/complex_diagnostics.ts:19:3\n\nTS2000 [ERROR]: Example 2\n values: undefined,\n ~~~~~~\n at /foo/bar.ts:129:3\n\nFound 2 errors.";
|
||||
assert_eq!(expected, strip_ansi_codes(&d.to_string()));
|
||||
}
|
||||
|
||||
|
|
|
@ -150,11 +150,7 @@ impl fmt::Display for JSError {
|
|||
"{}",
|
||||
&format_stack(
|
||||
true,
|
||||
format!(
|
||||
"{}: {}",
|
||||
colors::red_bold("error".to_string()),
|
||||
self.0.message.clone()
|
||||
),
|
||||
self.0.message.clone(),
|
||||
self.0.source_line.clone(),
|
||||
self.0.start_column,
|
||||
self.0.end_column,
|
||||
|
|
|
@ -626,7 +626,12 @@ pub fn main() {
|
|||
|
||||
let result = tokio_util::run_basic(fut);
|
||||
if let Err(err) = result {
|
||||
eprintln!("{}", err.to_string());
|
||||
let msg = format!(
|
||||
"{}: {}",
|
||||
colors::red_bold("error".to_string()),
|
||||
err.to_string(),
|
||||
);
|
||||
eprintln!("{}", msg);
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
[WILDCARD]error TS2552: Cannot find name 'consol'. Did you mean 'console'?
|
||||
[WILDCARD]
|
||||
error: TS2552 [ERROR]: Cannot find name 'consol'. Did you mean 'console'?
|
||||
consol.log("hello world!");
|
||||
~~~~~~
|
||||
at [WILDCARD]tests/038_checkjs.js:2:1
|
||||
|
@ -8,7 +9,7 @@ consol.log("hello world!");
|
|||
~~~~~~~
|
||||
at [WILDCARD]
|
||||
|
||||
error TS2552: Cannot find name 'Foo'. Did you mean 'foo'?
|
||||
TS2552 [ERROR]: Cannot find name 'Foo'. Did you mean 'foo'?
|
||||
const foo = new Foo();
|
||||
~~~
|
||||
at [WILDCARD]tests/038_checkjs.js:6:17
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[WILDCARD]Unsupported compiler options in "[WILDCARD]config.tsconfig.json"
|
||||
The following options were ignored:
|
||||
module, target
|
||||
error TS2532: Object is possibly 'undefined'.
|
||||
error: TS2532 [ERROR]: Object is possibly 'undefined'.
|
||||
if (map.get("bar").foo) {
|
||||
~~~~~~~~~~~~~~
|
||||
at [WILDCARD]tests/config.ts:3:5
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
[WILDCARD]error TS2322: Type '{ a: { b: { c(): { d: number; }; }; }; }' is not assignable to type '{ a: { b: { c(): { d: string; }; }; }; }'.
|
||||
[WILDCARD]
|
||||
error: TS2322 [ERROR]: Type '{ a: { b: { c(): { d: number; }; }; }; }' is not assignable to type '{ a: { b: { c(): { d: string; }; }; }; }'.
|
||||
The types of 'a.b.c().d' are incompatible between these types.
|
||||
Type 'number' is not assignable to type 'string'.
|
||||
x = y;
|
||||
|
|
|
@ -1 +1 @@
|
|||
Cannot resolve module "[WILDCARD]missing_file_name"
|
||||
error: Cannot resolve module "[WILDCARD]missing_file_name"
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
[WILDCARD]error TS2532: Object is possibly 'undefined'.
|
||||
[WILDCARD]
|
||||
error: TS2532 [ERROR]: Object is possibly 'undefined'.
|
||||
at [WILDCARD]tests/error_017_hide_long_source_ts.ts:2:1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
[WILDCARD]
|
||||
Remote module are not allowed to statically import local modules. Use dynamic import instead.
|
||||
error: Remote module are not allowed to statically import local modules. Use dynamic import instead.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[WILDCARD]
|
||||
error TS2339: Property 'loadavg' does not exist on type 'typeof Deno'.
|
||||
error: TS2339 [ERROR]: Property 'loadavg' does not exist on type 'typeof Deno'.
|
||||
console.log(Deno.loadavg);
|
||||
~~~~~~~
|
||||
at [WILDCARD]/cli/tests/unstable.ts:1:18
|
||||
|
|
Loading…
Add table
Reference in a new issue