Skip to content

Commit 07819be

Browse files
Better error message for missing edition or syntax at the first line of proto files.
PiperOrigin-RevId: 842907062
1 parent 1ba5192 commit 07819be

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/google/protobuf/compiler/parser.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,8 +654,8 @@ bool Parser::ParseSyntaxIdentifier(const FileDescriptorProto* file,
654654
has_edition = true;
655655
} else {
656656
DO(Consume("syntax",
657-
"File must begin with a syntax statement, e.g. 'syntax = "
658-
"\"proto2\";'."));
657+
"File must begin with an edition or syntax statement, e.g."
658+
" 'edition = \"2023\";'."));
659659
}
660660

661661
DO(Consume("="));

src/google/protobuf/compiler/parser_unittest.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,8 +1198,8 @@ TEST_F(ParseMessageTest, CanHandleErrorOnFirstToken) {
11981198
ExpectHasEarlyExitErrors(
11991199
"/",
12001200
"0:0: Expected top-level statement (e.g. \"message\").\n"
1201-
"0:0: File must begin with a syntax statement, e.g. 'syntax = "
1202-
"\"proto2\";'.\n");
1201+
"0:0: File must begin with an edition or syntax statement, "
1202+
"e.g. 'edition = \"2023\";'.\n");
12031203
}
12041204

12051205
// ===================================================================
@@ -1562,9 +1562,10 @@ typedef ParserTest ParseErrorTest;
15621562

15631563
TEST_F(ParseErrorTest, MissingSyntaxIdentifier) {
15641564
require_syntax_identifier_ = true;
1565-
ExpectHasEarlyExitErrors("message TestMessage {}",
1566-
"0:0: File must begin with a syntax statement, e.g. "
1567-
"'syntax = \"proto2\";'.\n");
1565+
ExpectHasEarlyExitErrors(
1566+
"message TestMessage {}",
1567+
"0:0: File must begin with an edition or syntax statement, e.g. "
1568+
"'edition = \"2023\";'.\n");
15681569
EXPECT_EQ("", parser_->GetSyntaxIdentifier());
15691570
}
15701571

0 commit comments

Comments
 (0)