-
Notifications
You must be signed in to change notification settings - Fork 13.4k
fix(45713) Improve error report summaries #45742
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
Changes from 1 commit
0638417
08906dd
1af84d2
f543c40
b2988e7
db56f9f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -101,24 +101,27 @@ namespace ts { | |
| return countWhere(diagnostics, diagnostic => diagnostic.category === DiagnosticCategory.Error); | ||
| } | ||
|
|
||
| export function getFilesInErrorForSummary(diagnostics: readonly Diagnostic[]) { | ||
| return filter(diagnostics, diagnostic => diagnostic.category === DiagnosticCategory.Error) | ||
| export function getFilesInErrorForSummary(diagnostics: readonly Diagnostic[]): (ReportFileInError | undefined)[] { | ||
| const filesInError = | ||
| filter(diagnostics, diagnostic => diagnostic.category === DiagnosticCategory.Error) | ||
| .map( | ||
| errorDiagnostic => { | ||
| if(errorDiagnostic.file === undefined) return; | ||
| return `${errorDiagnostic.file.fileName}`; | ||
| }) | ||
| .filter((value, index, self) => self !== undefined && self.indexOf(value) === index) | ||
| .map((fileName: string) => { | ||
| const diagnosticForFileName = find(diagnostics, diagnostic => | ||
| diagnostic.file !== undefined && diagnostic.file.fileName === fileName | ||
| ); | ||
|
|
||
| if(diagnosticForFileName !== undefined) { | ||
| const { line } = getLineAndCharacterOfPosition(diagnosticForFileName.file!, diagnosticForFileName.start!); | ||
| return `${fileName}:${line + 1}`; | ||
| } | ||
| }); | ||
| return filesInError.map((fileName: string) => { | ||
| const diagnosticForFileName = find(diagnostics, diagnostic => | ||
| diagnostic.file !== undefined && diagnostic.file.fileName === fileName | ||
| ); | ||
|
|
||
| if(diagnosticForFileName !== undefined) { | ||
| const { line } = getLineAndCharacterOfPosition(diagnosticForFileName.file!, diagnosticForFileName.start!); | ||
| return { | ||
| fileName, | ||
| line: line + 1, | ||
| }; | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| export function getWatchErrorSummaryDiagnosticMessage(errorCount: number) { | ||
|
|
@@ -129,24 +132,44 @@ namespace ts { | |
|
|
||
| export function getErrorSummaryText( | ||
| errorCount: number, | ||
| filesInError: readonly (string | undefined)[], | ||
| filesInError: readonly (ReportFileInError | undefined)[], | ||
| newLine: string | ||
| ) { | ||
| if (errorCount === 0) return ""; | ||
| const nonNilFiles = filesInError.filter(fileInError => fileInError !== undefined); | ||
| const distinctFileNamesWithLines = nonNilFiles.map(fileInError => `${fileInError!.fileName}:${fileInError!.line}`) | ||
| .filter((value, index, self) => self.indexOf(value) === index); | ||
| const d = errorCount === 1 ? | ||
| createCompilerDiagnostic( | ||
| filesInError[0] !== undefined ? | ||
| Diagnostics.Found_1_error_in_1 : | ||
| Diagnostics.Found_1_error, | ||
| errorCount, | ||
| filesInError[0]) : | ||
| distinctFileNamesWithLines[0]) : | ||
| createCompilerDiagnostic( | ||
| filesInError.length === 1 ? | ||
| Diagnostics.Found_0_errors_in_1_file : | ||
| Diagnostics.Found_0_errors_in_1_files, | ||
| distinctFileNamesWithLines.length === 0 ? | ||
| Diagnostics.Found_0_errors : | ||
| distinctFileNamesWithLines.length === 1 ? | ||
| Diagnostics.Found_0_errors_in_1_file : | ||
| Diagnostics.Found_0_errors_in_1_files, | ||
| errorCount, | ||
| filesInError.length); | ||
| return `${newLine}${flattenDiagnosticMessageText(d.messageText, newLine)}${newLine}${newLine}`; | ||
| distinctFileNamesWithLines.length); | ||
| return `${newLine}${flattenDiagnosticMessageText(d.messageText, newLine)}${newLine}${newLine}${errorCount > 1 ? createTabularErrorsDisplay(nonNilFiles) : ''}`; | ||
| } | ||
|
|
||
| function createTabularErrorsDisplay(filesInError: (ReportFileInError | undefined)[]) { | ||
| let tabularData = ""; | ||
| const distinctFiles = filesInError.filter((value, index, self) => index === self.findIndex(file => file!.fileName === value!.fileName)); | ||
| if(distinctFiles.length === 0) return tabularData; | ||
|
|
||
| const headerRow = "Errors Files\n"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This probably needs to be a localized message~
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we do that, (which I think we probably do need to do) then the numbers about length etc will need to not be hardcoded anymore. For example the Chinese version of "errors" might be 1-2 characters characters wide.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't think of that, yes this should probably be localised.
May I ask how you mean by "hardcoded" here? Do you mean we don't need to bother so much about left padding?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By hardcoding, I mean Armed with google translate, perhaps this is a reasonable design answer: Where tsc pulls out the longest length of a value from either the highest number of errors in a file or the translated word for "errors", allowing people to have a Does that feel reasonable to you?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That will work for me too. I'll work on it and see what I can come up with. Thank you for the explanation. |
||
| tabularData += headerRow; | ||
| distinctFiles.forEach(file => { | ||
| const errorCountForFile = countWhere(filesInError, fileInError => fileInError!.fileName === file!.fileName); | ||
| tabularData += ` ${errorCountForFile} ${file!.fileName}:${file!.line}\n`; | ||
| }) | ||
|
|
||
| return tabularData; | ||
| } | ||
|
|
||
| export function isBuilderProgram(program: Program | BuilderProgram): program is BuilderProgram { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,3 +67,5 @@ | |
|
|
||
| Found 2 errors in 1 file. | ||
|
|
||
| Errors Files | ||
| 2 tests/cases/compiler/deeplyNestedAssignabilityIssue.ts:22 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,3 +47,6 @@ | |
|
|
||
| Found 2 errors in 2 files. | ||
|
|
||
| Errors Files | ||
| 1 tests/cases/compiler/file1.ts:1 | ||
| 1 tests/cases/compiler/file2.ts:1 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,3 +87,6 @@ | |
|
|
||
| Found 6 errors in 2 files. | ||
|
|
||
| Errors Files | ||
| 3 tests/cases/compiler/file1.ts:2 | ||
| 3 tests/cases/compiler/file2.ts:2 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,3 +49,6 @@ | |
|
|
||
| Found 2 errors in 2 files. | ||
|
|
||
| Errors Files | ||
| 1 tests/cases/compiler/file1.ts:1 | ||
| 1 tests/cases/compiler/file2.ts:1 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,3 +94,6 @@ | |
|
|
||
| Found 6 errors in 2 files. | ||
|
|
||
| Errors Files | ||
| 3 tests/cases/compiler/file1.ts:3 | ||
| 3 tests/cases/compiler/file2.ts:4 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,3 +94,6 @@ | |
| } | ||
| Found 6 errors in 2 files. | ||
|
|
||
| Errors Files | ||
| 3 tests/cases/compiler/file1.ts:3 | ||
| 3 tests/cases/compiler/file2.ts:5 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,3 +58,6 @@ | |
| } | ||
| Found 2 errors in 2 files. | ||
|
|
||
| Errors Files | ||
| 1 tests/cases/compiler/file1.ts:1 | ||
| 1 tests/cases/compiler/file2.ts:3 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,3 +28,5 @@ | |
| } | ||
| Found 3 errors in 1 file. | ||
|
|
||
| Errors Files | ||
| 3 tests/cases/compiler/prettyFileWithErrorsAndTabs.ts:3 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -312,6 +312,9 @@ Output:: | |
|
|
||
| Found 2 errors in 2 files. | ||
|
|
||
| Errors Files | ||
| 1 /src/project/src/directUse.ts:2 | ||
| 1 /src/project/src/indirectUse.ts:2 | ||
| exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In comparison to the original I think we might need an extra newline after the table to be consistent with our newlines 👍🏻
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it, I'll add an extra newline. |
||
|
|
||
|
|
@@ -718,6 +721,10 @@ Output:: | |
|
|
||
| Found 3 errors in 3 files. | ||
|
|
||
| Errors Files | ||
| 1 /src/project/src/directUse.ts:2 | ||
| 1 /src/project/src/indirectUse.ts:2 | ||
| 1 /src/project/src/noChangeFileWithEmitSpecificError.ts:1 | ||
| exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated | ||
|
|
||
|
|
||
|
|
@@ -931,6 +938,10 @@ Output:: | |
|
|
||
| Found 3 errors in 3 files. | ||
|
|
||
| Errors Files | ||
| 1 /src/project/src/directUse.ts:2 | ||
| 1 /src/project/src/indirectUse.ts:2 | ||
| 1 /src/project/src/noChangeFileWithEmitSpecificError.ts:1 | ||
| exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated | ||
|
|
||
|
|
||
|
|
@@ -965,6 +976,9 @@ Output:: | |
|
|
||
| Found 2 errors in 2 files. | ||
|
|
||
| Errors Files | ||
| 1 /src/project/src/directUse.ts:2 | ||
| 1 /src/project/src/indirectUse.ts:2 | ||
| exitCode:: ExitStatus.DiagnosticsPresent_OutputsSkipped | ||
|
|
||
|
|
||
|
|
@@ -999,6 +1013,9 @@ Output:: | |
|
|
||
| Found 2 errors in 2 files. | ||
|
|
||
| Errors Files | ||
| 1 /src/project/src/directUse.ts:2 | ||
| 1 /src/project/src/indirectUse.ts:2 | ||
| exitCode:: ExitStatus.DiagnosticsPresent_OutputsSkipped | ||
|
|
||
|
|
||
|
|
@@ -1038,6 +1055,10 @@ Output:: | |
|
|
||
| Found 3 errors in 3 files. | ||
|
|
||
| Errors Files | ||
| 1 /src/project/src/directUse.ts:2 | ||
| 1 /src/project/src/indirectUse.ts:2 | ||
| 1 /src/project/src/noChangeFileWithEmitSpecificError.ts:1 | ||
| exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is quite a dense statement, not sure I have any good ideas off the top off my head on how to improve it though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll have a look back at it and see what I could do. I also try to avoid double ternaries if I can avoid it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about something like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me, wes also said this is pretty common in the codebase, so the original is also fine 👍🏻