Skip to content

Commit 9e2b7ad

Browse files
mickey-stringermickey-stringer
andauthored
fix(47492): more detailed parseTryStatement error message (#47504)
* more detailed parseTryStatement error message * move custom error to diagnosticMessages.json * update error code Co-authored-by: mickey-stringer <[email protected]>
1 parent ad5ca67 commit 9e2b7ad

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,6 +1409,10 @@
14091409
"category": "Error",
14101410
"code": 1471
14111411
},
1412+
"'catch' or 'finally' expected.": {
1413+
"category": "Error",
1414+
"code": 1472
1415+
},
14121416

14131417
"The types of '{0}' are incompatible between these types.": {
14141418
"category": "Error",

src/compiler/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6080,7 +6080,7 @@ namespace ts {
60806080
// one out no matter what.
60816081
let finallyBlock: Block | undefined;
60826082
if (!catchClause || token() === SyntaxKind.FinallyKeyword) {
6083-
parseExpected(SyntaxKind.FinallyKeyword);
6083+
parseExpected(SyntaxKind.FinallyKeyword, Diagnostics.catch_or_finally_expected);
60846084
finallyBlock = parseBlock(/*ignoreMissingOpenBrace*/ false);
60856085
}
60866086

tests/baselines/reference/invalidTryStatements.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
tests/cases/conformance/statements/tryStatements/invalidTryStatements.ts(2,5): error TS1005: 'try' expected.
2-
tests/cases/conformance/statements/tryStatements/invalidTryStatements.ts(6,12): error TS1005: 'finally' expected.
2+
tests/cases/conformance/statements/tryStatements/invalidTryStatements.ts(6,12): error TS1472: 'catch' or 'finally' expected.
33
tests/cases/conformance/statements/tryStatements/invalidTryStatements.ts(10,5): error TS1005: 'try' expected.
44
tests/cases/conformance/statements/tryStatements/invalidTryStatements.ts(11,5): error TS1005: 'try' expected.
55
tests/cases/conformance/statements/tryStatements/invalidTryStatements.ts(15,5): error TS1005: 'try' expected.
@@ -17,7 +17,7 @@ tests/cases/conformance/statements/tryStatements/invalidTryStatements.ts(19,20):
1717

1818
try { }; // error missing finally
1919
~
20-
!!! error TS1005: 'finally' expected.
20+
!!! error TS1472: 'catch' or 'finally' expected.
2121
}
2222

2323
function fn2() {

0 commit comments

Comments
 (0)