Skip to content

Commit

Permalink
Convert "missing syntax" warning to an actual warning
Browse files Browse the repository at this point in the history
For some reason this warning was emitted as a log message rather than a
structured warning. Convert it to use the AddWarning API so that it gets
emitted with a file and line number by protoc, and is visible via the
error collection interface during programmatic use.
  • Loading branch information
benesch committed Apr 17, 2022
1 parent 0b5eea9 commit e1dac2b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/google/protobuf/compiler/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -643,10 +643,11 @@ bool Parser::Parse(io::Tokenizer* input, FileDescriptorProto* file) {
// Store the syntax into the file.
if (file != nullptr) file->set_syntax(syntax_identifier_);
} else if (!stop_after_syntax_identifier_) {
GOOGLE_LOG(WARNING) << "No syntax specified for the proto file: " << file->name()
<< ". Please use 'syntax = \"proto2\";' "
<< "or 'syntax = \"proto3\";' to specify a syntax "
<< "version. (Defaulted to proto2 syntax.)";
AddWarning(
"No syntax specified. Please use 'syntax = \"proto2\";' or "
"'syntax = \"proto3\";' to specify a syntax version. "
"(Defaulted to proto2 syntax.)"
);
syntax_identifier_ = "proto2";
}

Expand Down
2 changes: 1 addition & 1 deletion src/google/protobuf/compiler/parser_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ TEST_F(ParserTest, WarnIfSyntaxIdentifierOmmitted) {
FileDescriptorProto file;
CaptureTestStderr();
EXPECT_TRUE(parser_->Parse(input_.get(), &file));
EXPECT_TRUE(GetCapturedTestStderr().find("No syntax specified") !=
EXPECT_TRUE(error_collector_.warning_.find("No syntax specified") !=
std::string::npos);
}

Expand Down

0 comments on commit e1dac2b

Please sign in to comment.