Skip to content

Commit d7cb52b

Browse files
Dan Rubelcommit-bot@chromium.org
authored andcommitted
capture more info to debug 37528
This updates the exception message to capture more information about where the exception is occurring. Hopefully that information can be used to fix #37528 Change-Id: Iaf10395091f8bd8b540dddc59001f23b6dc6a073 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/109920 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Dan Rubel <[email protected]>
1 parent d6c85f4 commit d7cb52b

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

pkg/analyzer/test/generated/parser_fasta_test.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,22 @@ main() { // missing async
10951095
]);
10961096
}
10971097

1098+
void test_missing_closing_bracket_issue37528() {
1099+
final code = '\${foo';
1100+
createParser(code);
1101+
final result = fasta.scanString(code);
1102+
expect(result.hasErrors, isTrue);
1103+
var token = _parserProxy.fastaParser.syntheticPreviousToken(result.tokens);
1104+
try {
1105+
_parserProxy.fastaParser.parseExpression(token);
1106+
// TODO(danrubel): Replace this test once root cause is found
1107+
fail('exception expected');
1108+
} catch (e) {
1109+
var msg = e.toString();
1110+
expect(msg.contains('test_missing_closing_bracket_issue37528'), isTrue);
1111+
}
1112+
}
1113+
10981114
void test_partialNamedConstructor() {
10991115
parseCompilationUnit('class C { C. }', errors: [
11001116
expectedError(ParserErrorCode.MISSING_IDENTIFIER, 13, 1),

pkg/front_end/lib/src/fasta/scanner/error_token.dart

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,23 @@ abstract class ErrorToken extends SimpleToken {
7272
@override
7373
int get length => 1;
7474

75-
String get lexeme => throw assertionMessage.message;
75+
String get lexeme {
76+
var errorMsg = assertionMessage.message;
77+
78+
// Attempt to include the location which is calling the parser
79+
// in an effort to debug https://github.com/dart-lang/sdk/issues/37528
80+
var pattern = RegExp('^#[0-9]* *Parser');
81+
var traceLines = StackTrace.current.toString().split('\n');
82+
for (int index = traceLines.length - 2; index >= 0; --index) {
83+
var line = traceLines[index];
84+
if (line.startsWith(pattern)) {
85+
errorMsg = '$errorMsg - ${traceLines[index + 1]}';
86+
break;
87+
}
88+
}
89+
90+
throw errorMsg;
91+
}
7692

7793
Message get assertionMessage;
7894

0 commit comments

Comments
 (0)