Skip to content

Commit 08906dd

Browse files
committed
fixup! Improve error report summaries (#45713)
1 parent 0638417 commit 08906dd

24 files changed

+182
-27
lines changed

src/compiler/tsbuildPublic.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,12 @@ namespace ts {
7676
return fileExtensionIs(fileName, Extension.Dts);
7777
}
7878

79-
export type ReportEmitErrorSummary = (errorCount: number, filesInError: (string | undefined)[]) => void;
79+
export type ReportEmitErrorSummary = (errorCount: number, filesInError: (ReportFileInError | undefined)[]) => void;
80+
81+
export interface ReportFileInError {
82+
fileName: string;
83+
line: number;
84+
}
8085

8186
export interface SolutionBuilderHostBase<T extends BuilderProgram> extends ProgramHost<T> {
8287
createDirectory?(path: string): void;
@@ -2002,7 +2007,7 @@ namespace ts {
20022007
const canReportSummary = state.watch || !!state.host.reportErrorSummary;
20032008
const { diagnostics } = state;
20042009
let totalErrors = 0;
2005-
let filesInError: (string | undefined)[] = [];
2010+
let filesInError: (ReportFileInError | undefined)[] = [];
20062011
if (isCircularBuildOrder(buildOrder)) {
20072012
reportBuildQueue(state, buildOrder.buildOrder);
20082013
reportErrors(state, buildOrder.circularDiagnostics);

src/compiler/watch.ts

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -101,24 +101,27 @@ namespace ts {
101101
return countWhere(diagnostics, diagnostic => diagnostic.category === DiagnosticCategory.Error);
102102
}
103103

104-
export function getFilesInErrorForSummary(diagnostics: readonly Diagnostic[]) {
105-
return filter(diagnostics, diagnostic => diagnostic.category === DiagnosticCategory.Error)
104+
export function getFilesInErrorForSummary(diagnostics: readonly Diagnostic[]): (ReportFileInError | undefined)[] {
105+
const filesInError =
106+
filter(diagnostics, diagnostic => diagnostic.category === DiagnosticCategory.Error)
106107
.map(
107108
errorDiagnostic => {
108109
if(errorDiagnostic.file === undefined) return;
109110
return `${errorDiagnostic.file.fileName}`;
110-
})
111-
.filter((value, index, self) => self !== undefined && self.indexOf(value) === index)
112-
.map((fileName: string) => {
113-
const diagnosticForFileName = find(diagnostics, diagnostic =>
114-
diagnostic.file !== undefined && diagnostic.file.fileName === fileName
115-
);
116-
117-
if(diagnosticForFileName !== undefined) {
118-
const { line } = getLineAndCharacterOfPosition(diagnosticForFileName.file!, diagnosticForFileName.start!);
119-
return `${fileName}:${line + 1}`;
120-
}
121111
});
112+
return filesInError.map((fileName: string) => {
113+
const diagnosticForFileName = find(diagnostics, diagnostic =>
114+
diagnostic.file !== undefined && diagnostic.file.fileName === fileName
115+
);
116+
117+
if(diagnosticForFileName !== undefined) {
118+
const { line } = getLineAndCharacterOfPosition(diagnosticForFileName.file!, diagnosticForFileName.start!);
119+
return {
120+
fileName,
121+
line: line + 1,
122+
};
123+
}
124+
});
122125
}
123126

124127
export function getWatchErrorSummaryDiagnosticMessage(errorCount: number) {
@@ -129,24 +132,44 @@ namespace ts {
129132

130133
export function getErrorSummaryText(
131134
errorCount: number,
132-
filesInError: readonly (string | undefined)[],
135+
filesInError: readonly (ReportFileInError | undefined)[],
133136
newLine: string
134137
) {
135138
if (errorCount === 0) return "";
139+
const nonNilFiles = filesInError.filter(fileInError => fileInError !== undefined);
140+
const distinctFileNamesWithLines = nonNilFiles.map(fileInError => `${fileInError!.fileName}:${fileInError!.line}`)
141+
.filter((value, index, self) => self.indexOf(value) === index);
136142
const d = errorCount === 1 ?
137143
createCompilerDiagnostic(
138144
filesInError[0] !== undefined ?
139145
Diagnostics.Found_1_error_in_1 :
140146
Diagnostics.Found_1_error,
141147
errorCount,
142-
filesInError[0]) :
148+
distinctFileNamesWithLines[0]) :
143149
createCompilerDiagnostic(
144-
filesInError.length === 1 ?
145-
Diagnostics.Found_0_errors_in_1_file :
146-
Diagnostics.Found_0_errors_in_1_files,
150+
distinctFileNamesWithLines.length === 0 ?
151+
Diagnostics.Found_0_errors :
152+
distinctFileNamesWithLines.length === 1 ?
153+
Diagnostics.Found_0_errors_in_1_file :
154+
Diagnostics.Found_0_errors_in_1_files,
147155
errorCount,
148-
filesInError.length);
149-
return `${newLine}${flattenDiagnosticMessageText(d.messageText, newLine)}${newLine}${newLine}`;
156+
distinctFileNamesWithLines.length);
157+
return `${newLine}${flattenDiagnosticMessageText(d.messageText, newLine)}${newLine}${newLine}${errorCount > 1 ? createTabularErrorsDisplay(nonNilFiles) : ''}`;
158+
}
159+
160+
function createTabularErrorsDisplay(filesInError: (ReportFileInError | undefined)[]) {
161+
let tabularData = "";
162+
const distinctFiles = filesInError.filter((value, index, self) => index === self.findIndex(file => file!.fileName === value!.fileName));
163+
if(distinctFiles.length === 0) return tabularData;
164+
165+
const headerRow = "Errors Files\n";
166+
tabularData += headerRow;
167+
distinctFiles.forEach(file => {
168+
const errorCountForFile = countWhere(filesInError, fileInError => fileInError!.fileName === file!.fileName);
169+
tabularData += ` ${errorCountForFile} ${file!.fileName}:${file!.line}\n`;
170+
})
171+
172+
return tabularData;
150173
}
151174

152175
export function isBuilderProgram(program: Program | BuilderProgram): program is BuilderProgram {

src/testRunner/unittests/tscWatch/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ namespace ts.tscWatch {
207207
export function checkNormalBuildErrors(
208208
host: WatchedSystem,
209209
errors: readonly Diagnostic[] | readonly string[],
210-
files: readonly string[],
210+
files: readonly ReportFileInError[],
211211
reportErrorSummary?: boolean
212212
) {
213213
checkOutputErrors(

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5249,7 +5249,11 @@ declare namespace ts {
52495249
traceResolution?: boolean;
52505250
[option: string]: CompilerOptionsValue | undefined;
52515251
}
5252-
type ReportEmitErrorSummary = (errorCount: number, filesInError: (string | undefined)[]) => void;
5252+
type ReportEmitErrorSummary = (errorCount: number, filesInError: (ReportFileInError | undefined)[]) => void;
5253+
interface ReportFileInError {
5254+
fileName: string;
5255+
line: number;
5256+
}
52535257
interface SolutionBuilderHostBase<T extends BuilderProgram> extends ProgramHost<T> {
52545258
createDirectory?(path: string): void;
52555259
/**

tests/baselines/reference/api/typescript.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5249,7 +5249,11 @@ declare namespace ts {
52495249
traceResolution?: boolean;
52505250
[option: string]: CompilerOptionsValue | undefined;
52515251
}
5252-
type ReportEmitErrorSummary = (errorCount: number, filesInError: (string | undefined)[]) => void;
5252+
type ReportEmitErrorSummary = (errorCount: number, filesInError: (ReportFileInError | undefined)[]) => void;
5253+
interface ReportFileInError {
5254+
fileName: string;
5255+
line: number;
5256+
}
52535257
interface SolutionBuilderHostBase<T extends BuilderProgram> extends ProgramHost<T> {
52545258
createDirectory?(path: string): void;
52555259
/**

tests/baselines/reference/deeplyNestedAssignabilityIssue.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,5 @@
6767

6868
Found 2 errors in 1 file.
6969

70+
Errors Files
71+
2 tests/cases/compiler/deeplyNestedAssignabilityIssue.ts:22

tests/baselines/reference/duplicateIdentifierRelatedSpans1.errors.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,7 @@
9494

9595
Found 6 errors in 3 files.
9696

97+
Errors Files
98+
2 tests/cases/compiler/file1.ts:1
99+
2 tests/cases/compiler/file2.ts:1
100+
2 tests/cases/compiler/file3.ts:1

tests/baselines/reference/duplicateIdentifierRelatedSpans2.errors.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,6 @@
4747

4848
Found 2 errors in 2 files.
4949

50+
Errors Files
51+
1 tests/cases/compiler/file1.ts:1
52+
1 tests/cases/compiler/file2.ts:1

tests/baselines/reference/duplicateIdentifierRelatedSpans3.errors.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,6 @@
8787

8888
Found 6 errors in 2 files.
8989

90+
Errors Files
91+
3 tests/cases/compiler/file1.ts:2
92+
3 tests/cases/compiler/file2.ts:2

tests/baselines/reference/duplicateIdentifierRelatedSpans4.errors.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,6 @@
4949

5050
Found 2 errors in 2 files.
5151

52+
Errors Files
53+
1 tests/cases/compiler/file1.ts:1
54+
1 tests/cases/compiler/file2.ts:1

0 commit comments

Comments
 (0)