mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 07:14:47 -05:00
hide source line if error message longer than 150 chars (#4487)
This commit is contained in:
parent
addfdc4cd0
commit
3d228f5f9e
6 changed files with 29 additions and 2 deletions
|
@ -10,6 +10,8 @@ use std::error::Error;
|
|||
use std::fmt;
|
||||
use std::ops::Deref;
|
||||
|
||||
const SOURCE_ABBREV_THRESHOLD: usize = 150;
|
||||
|
||||
/// A trait which specifies parts of a diagnostic like item needs to be able to
|
||||
/// generate to conform its display to other diagnostic like items
|
||||
pub trait DisplayFormatter {
|
||||
|
@ -74,8 +76,9 @@ pub fn format_maybe_source_line(
|
|||
|
||||
let source_line = source_line.as_ref().unwrap();
|
||||
// sometimes source_line gets set with an empty string, which then outputs
|
||||
// an empty source line when displayed, so need just short circuit here
|
||||
if source_line.is_empty() {
|
||||
// an empty source line when displayed, so need just short circuit here.
|
||||
// Also short-circuit on error line too long.
|
||||
if source_line.is_empty() || source_line.len() > SOURCE_ABBREV_THRESHOLD {
|
||||
return "".to_string();
|
||||
}
|
||||
|
||||
|
|
2
cli/tests/error_017_hide_long_source_ts.ts
Normal file
2
cli/tests/error_017_hide_long_source_ts.ts
Normal file
|
@ -0,0 +1,2 @@
|
|||
const LONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONG = undefined;
|
||||
LONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONG.a;
|
3
cli/tests/error_017_hide_long_source_ts.ts.out
Normal file
3
cli/tests/error_017_hide_long_source_ts.ts.out
Normal file
|
@ -0,0 +1,3 @@
|
|||
[WILDCARD]error TS2532: Object is possibly 'undefined'.
|
||||
|
||||
► file:///[WILDCARD]cli/tests/error_017_hide_long_source_ts.ts:2:1
|
2
cli/tests/error_018_hide_long_source_js.js
Normal file
2
cli/tests/error_018_hide_long_source_js.js
Normal file
|
@ -0,0 +1,2 @@
|
|||
const LONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONG = undefined;
|
||||
LONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONG.a;
|
3
cli/tests/error_018_hide_long_source_js.js.out
Normal file
3
cli/tests/error_018_hide_long_source_js.js.out
Normal file
|
@ -0,0 +1,3 @@
|
|||
error: Uncaught TypeError: Cannot read property 'a' of undefined
|
||||
► file:///[WILDCARD]cli/tests/error_018_hide_long_source_js.js:2:206
|
||||
at file:///[WILDCARD]cli/tests/error_018_hide_long_source_js.js:2:206
|
|
@ -1274,6 +1274,20 @@ itest!(error_016_dynamic_import_permissions2 {
|
|||
http_server: true,
|
||||
});
|
||||
|
||||
itest!(error_017_hide_long_source_ts {
|
||||
args: "--reload error_017_hide_long_source_ts.ts",
|
||||
output: "error_017_hide_long_source_ts.ts.out",
|
||||
check_stderr: true,
|
||||
exit_code: 1,
|
||||
});
|
||||
|
||||
itest!(error_018_hide_long_source_js {
|
||||
args: "error_018_hide_long_source_js.js",
|
||||
output: "error_018_hide_long_source_js.js.out",
|
||||
check_stderr: true,
|
||||
exit_code: 1,
|
||||
});
|
||||
|
||||
itest!(error_stack {
|
||||
args: "run --reload error_stack.ts",
|
||||
check_stderr: true,
|
||||
|
|
Loading…
Reference in a new issue