Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b73558d

Browse filesBrowse files
Merge pull request microsoft#508 from Microsoft/printDiagnosticCodes
Emit error codes when reporting diagnostics.
2 parents e6cd3e1 + 48c6bdb commit b73558d
Copy full SHA for b73558d

30 files changed

+94-79Lines changed: 94 additions & 79 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/compiler/tsc.ts‎

Copy file name to clipboardExpand all lines: src/compiler/tsc.ts
+9-4Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,18 @@ module ts {
8686
}
8787

8888
function reportDiagnostic(diagnostic: Diagnostic) {
89+
var output = "";
90+
8991
if (diagnostic.file) {
9092
var loc = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start);
91-
sys.write(diagnostic.file.filename + "(" + loc.line + "," + loc.character + "): " + diagnostic.messageText + sys.newLine);
92-
}
93-
else {
94-
sys.write(diagnostic.messageText + sys.newLine);
93+
94+
output += diagnostic.file.filename + "(" + loc.line + "," + loc.character + "): ";
9595
}
96+
97+
var category = DiagnosticCategory[diagnostic.category].toLowerCase();
98+
output += category + " TS" + diagnostic.code + ": " + diagnostic.messageText + sys.newLine;
99+
100+
sys.write(output);
96101
}
97102

98103
function reportDiagnostics(diagnostics: Diagnostic[]) {
Collapse file

‎src/harness/harness.ts‎

Copy file name to clipboardExpand all lines: src/harness/harness.ts
+27-17Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ module Harness {
563563
private compileOptions: ts.CompilerOptions;
564564
private settings: Harness.TestCaseParser.CompilerSetting[] = [];
565565

566-
private lastErrors: MinimalDiagnostic[];
566+
private lastErrors: HarnessDiagnostic[];
567567

568568
public reset() {
569569
this.inputFiles = [];
@@ -750,7 +750,7 @@ module Harness {
750750
emitResult = checker.emitFiles();
751751
}
752752

753-
var errors: MinimalDiagnostic[] = [];
753+
var errors: HarnessDiagnostic[] = [];
754754
program.getDiagnostics().concat(checker.getDiagnostics()).concat(emitResult ? emitResult.errors : []).forEach(err => {
755755
// TODO: new compiler formats errors after this point to add . and newlines so we'll just do it manually for now
756756
errors.push(getMinimalDiagnostic(err));
@@ -768,35 +768,43 @@ module Harness {
768768
}
769769
}
770770

771-
export function getMinimalDiagnostic(err: ts.Diagnostic): MinimalDiagnostic {
771+
export function getMinimalDiagnostic(err: ts.Diagnostic): HarnessDiagnostic {
772772
var errorLineInfo = err.file ? err.file.getLineAndCharacterFromPosition(err.start) : { line: 0, character: 0 };
773-
return { filename: err.file && err.file.filename, start: err.start, end: err.start + err.length, line: errorLineInfo.line, character: errorLineInfo.character, message: err.messageText };
773+
return {
774+
filename: err.file && err.file.filename,
775+
start: err.start,
776+
end: err.start + err.length,
777+
line: errorLineInfo.line,
778+
character: errorLineInfo.character,
779+
message: err.messageText,
780+
category: ts.DiagnosticCategory[err.category].toLowerCase(),
781+
code: err.code
782+
};
774783
}
775784

776-
export function minimalDiagnosticsToString(diagnostics: MinimalDiagnostic[]) {
777-
// This is copied from tsc.ts's reportError to replicate what tsc does
778-
var errors = "";
785+
export function minimalDiagnosticsToString(diagnostics: HarnessDiagnostic[]) {
786+
// This is basically copied from tsc.ts's reportError to replicate what tsc does
787+
var errorOutput = "";
779788
ts.forEach(diagnostics, diagnotic => {
780789
if (diagnotic.filename) {
781-
errors += diagnotic.filename + "(" + diagnotic.line + "," + diagnotic.character + "): " + diagnotic.message + sys.newLine;
782-
}
783-
else {
784-
errors += diagnotic.message + sys.newLine;
790+
errorOutput += diagnotic.filename + "(" + diagnotic.line + "," + diagnotic.character + "): ";
785791
}
792+
793+
errorOutput += diagnotic.category + " TS" + diagnotic.code + ": " + diagnotic.message + sys.newLine;
786794
});
787795

788-
return errors;
796+
return errorOutput;
789797
}
790798

791799
export function getErrorBaseline(inputFiles: { unitName: string; content: string }[],
792-
diagnostics: MinimalDiagnostic[]
800+
diagnostics: HarnessDiagnostic[]
793801
) {
794802

795803
var outputLines: string[] = [];
796804
// Count up all the errors we find so we don't miss any
797805
var totalErrorsReported = 0;
798806

799-
function outputErrorText(error: Harness.Compiler.MinimalDiagnostic) {
807+
function outputErrorText(error: Harness.Compiler.HarnessDiagnostic) {
800808
var errLines = RunnerBase.removeFullPaths(error.message)
801809
.split('\n')
802810
.map(s => s.length > 0 && s.charAt(s.length - 1) === '\r' ? s.substr(0, s.length - 1) : s)
@@ -916,13 +924,15 @@ module Harness {
916924
//harnessCompiler.compileString(code, unitName, callback);
917925
}
918926

919-
export interface MinimalDiagnostic {
927+
export interface HarnessDiagnostic {
920928
filename: string;
921929
start: number;
922930
end: number;
923931
line: number;
924932
character: number;
925933
message: string;
934+
category: string;
935+
code: number;
926936
}
927937

928938
export interface GeneratedFile {
@@ -950,13 +960,13 @@ module Harness {
950960
/** Contains the code and errors of a compilation and some helper methods to check its status. */
951961
export class CompilerResult {
952962
public files: GeneratedFile[] = [];
953-
public errors: MinimalDiagnostic[] = [];
963+
public errors: HarnessDiagnostic[] = [];
954964
public declFilesCode: GeneratedFile[] = [];
955965
public sourceMaps: GeneratedFile[] = [];
956966
public sourceMapRecord: string;
957967

958968
/** @param fileResults an array of strings for the fileName and an ITextWriter with its code */
959-
constructor(fileResults: GeneratedFile[], errors: MinimalDiagnostic[], sourceMapRecordLines: string[]) {
969+
constructor(fileResults: GeneratedFile[], errors: HarnessDiagnostic[], sourceMapRecordLines: string[]) {
960970
var lines: string[] = [];
961971

962972
fileResults.forEach(emittedFile => {
Collapse file

‎tests/baselines/reference/project/cantFindTheModule/amd/cantFindTheModule.errors.txt‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/project/cantFindTheModule/amd/cantFindTheModule.errors.txt
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
decl.ts(1,26): Cannot find external module './foo/bar.js'.
2-
decl.ts(2,26): Cannot find external module 'baz'.
3-
decl.ts(3,26): Cannot find external module './baz'.
1+
decl.ts(1,26): error TS2307: Cannot find external module './foo/bar.js'.
2+
decl.ts(2,26): error TS2307: Cannot find external module 'baz'.
3+
decl.ts(3,26): error TS2307: Cannot find external module './baz'.
44

55

66
==== decl.ts (3 errors) ====
Collapse file

‎tests/baselines/reference/project/cantFindTheModule/node/cantFindTheModule.errors.txt‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/project/cantFindTheModule/node/cantFindTheModule.errors.txt
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
decl.ts(1,26): Cannot find external module './foo/bar.js'.
2-
decl.ts(2,26): Cannot find external module 'baz'.
3-
decl.ts(3,26): Cannot find external module './baz'.
1+
decl.ts(1,26): error TS2307: Cannot find external module './foo/bar.js'.
2+
decl.ts(2,26): error TS2307: Cannot find external module 'baz'.
3+
decl.ts(3,26): error TS2307: Cannot find external module './baz'.
44

55

66
==== decl.ts (3 errors) ====
Collapse file

‎tests/baselines/reference/project/declareVariableCollision/amd/declareVariableCollision.errors.txt‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/project/declareVariableCollision/amd/declareVariableCollision.errors.txt
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
in2.d.ts(1,8): Duplicate identifier 'a'.
1+
in2.d.ts(1,8): error TS2300: Duplicate identifier 'a'.
22

33

44
==== decl.d.ts (0 errors) ====
Collapse file

‎tests/baselines/reference/project/declareVariableCollision/node/declareVariableCollision.errors.txt‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/project/declareVariableCollision/node/declareVariableCollision.errors.txt
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
in2.d.ts(1,8): Duplicate identifier 'a'.
1+
in2.d.ts(1,8): error TS2300: Duplicate identifier 'a'.
22

33

44
==== decl.d.ts (0 errors) ====
Collapse file

‎tests/baselines/reference/project/intReferencingExtAndInt/amd/intReferencingExtAndInt.errors.txt‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/project/intReferencingExtAndInt/amd/intReferencingExtAndInt.errors.txt
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
internal2.ts(2,2): Import declarations in an internal module cannot reference an external module.
1+
internal2.ts(2,2): error TS1147: Import declarations in an internal module cannot reference an external module.
22

33

44
==== internal2.ts (1 errors) ====
Collapse file

‎tests/baselines/reference/project/intReferencingExtAndInt/node/intReferencingExtAndInt.errors.txt‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/project/intReferencingExtAndInt/node/intReferencingExtAndInt.errors.txt
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
internal2.ts(2,2): Import declarations in an internal module cannot reference an external module.
1+
internal2.ts(2,2): error TS1147: Import declarations in an internal module cannot reference an external module.
22

33

44
==== internal2.ts (1 errors) ====
Collapse file

‎tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/amd/mapRootSourceRootWithNoSourceMapOption.errors.txt‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/amd/mapRootSourceRootWithNoSourceMapOption.errors.txt
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Option mapRoot cannot be specified without specifying sourcemap option.
2-
Option sourceRoot cannot be specified without specifying sourcemap option.
1+
error TS5038: Option mapRoot cannot be specified without specifying sourcemap option.
2+
error TS5039: Option sourceRoot cannot be specified without specifying sourcemap option.
33

44

55
!!! Option mapRoot cannot be specified without specifying sourcemap option.
Collapse file

‎tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/node/mapRootSourceRootWithNoSourceMapOption.errors.txt‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/node/mapRootSourceRootWithNoSourceMapOption.errors.txt
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Option mapRoot cannot be specified without specifying sourcemap option.
2-
Option sourceRoot cannot be specified without specifying sourcemap option.
1+
error TS5038: Option mapRoot cannot be specified without specifying sourcemap option.
2+
error TS5039: Option sourceRoot cannot be specified without specifying sourcemap option.
33

44

55
!!! Option mapRoot cannot be specified without specifying sourcemap option.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.