Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

errors: hide source line if longer than 150 chars #4487

Merged
merged 1 commit into from
Mar 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions cli/fmt_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
}

Expand Down
2 changes: 2 additions & 0 deletions cli/tests/error_017_hide_long_source_ts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const LONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONG = undefined;
LONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONG.a;
3 changes: 3 additions & 0 deletions cli/tests/error_017_hide_long_source_ts.ts.out
Original file line number Diff line number Diff line change
@@ -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 changes: 2 additions & 0 deletions cli/tests/error_018_hide_long_source_js.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions cli/tests/error_018_hide_long_source_js.js.out
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions cli/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down