Skip to content

Commit 1794717

Browse files
Abseil Teamcopybara-github
authored andcommitted
absl::flags: Stop echoing file content in flagfile parsing errors
Modified ArgsList::ReadFromFlagfile to redact the content of unexpected lines from error messages. \ PiperOrigin-RevId: 845327732 Change-Id: I6e0bf8f443b534cc9fa14e214e0d275e30116261
1 parent 4ab5394 commit 1794717

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

absl/flags/parse.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,10 @@ bool ArgsList::ReadFromFlagfile(const std::string& flag_file_name) {
206206

207207
std::string line;
208208
bool success = true;
209+
int line_number = 0;
209210

210211
while (std::getline(flag_file, line)) {
212+
line_number++;
211213
absl::string_view stripped = absl::StripLeadingAsciiWhitespace(line);
212214

213215
if (stripped.empty() || stripped[0] == '#') {
@@ -229,8 +231,8 @@ bool ArgsList::ReadFromFlagfile(const std::string& flag_file_name) {
229231
}
230232

231233
flags_internal::ReportUsageError(
232-
absl::StrCat("Unexpected line in the flagfile ", flag_file_name, ": ",
233-
line),
234+
absl::StrCat("Unexpected line ", line_number, " in the flagfile ",
235+
flag_file_name),
234236
true);
235237

236238
success = false;

absl/flags/parse_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ TEST_F(ParseDeathTest, TestInvalidFlagfiles) {
827827
flagfile_flag),
828828
};
829829
EXPECT_DEATH_IF_SUPPORTED(InvokeParse(in_args5),
830-
"Unexpected line in the flagfile .*: \\*bin\\*");
830+
"Unexpected line 2 in the flagfile .*");
831831
}
832832

833833
// --------------------------------------------------------------------

0 commit comments

Comments
 (0)