Skip to content

Commit

Permalink
#Centipede LOG more information when a local file read fails.
Browse files Browse the repository at this point in the history
We sometimes see reading a local file fails but the CHECK() statement does not provide sufficient information to debug this problem.

PiperOrigin-RevId: 577032491
  • Loading branch information
dougkwan authored and copybara-github committed Oct 27, 2023
1 parent 7be1800 commit 81403f3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions centipede/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ cc_library(
":feature",
":logging",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/log:check",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
"@com_google_absl//absl/synchronization",
Expand Down
9 changes: 8 additions & 1 deletion centipede/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,19 @@
#include <algorithm>
#include <atomic>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio> // NOLINT(popen)
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <filesystem> // NOLINT
#include <fstream>
#include <functional>
#include <ios>
#include <queue>
#include <random>
#include <sstream>
#include <string>
#include <string_view>
#include <thread> // NOLINT(build/c++11)
Expand All @@ -41,6 +46,7 @@
#include "absl/base/attributes.h"
#include "absl/base/const_init.h"
#include "absl/base/thread_annotations.h"
#include "absl/log/check.h"
#include "absl/strings/ascii.h"
#include "absl/strings/str_format.h"
#include "absl/strings/str_replace.h"
Expand Down Expand Up @@ -85,7 +91,8 @@ void ReadFromLocalFile(std::string_view file_path, Container &data) {
CHECK_EQ(size % sizeof(data[0]), 0);
data.resize(size / sizeof(data[0]));
f.read(reinterpret_cast<char *>(data.data()), size);
CHECK(f) << "Failed to read from local file: " << file_path;
CHECK(f) << "Failed to read from local file: " << VV(file_path) << VV(f.eof())
<< VV(f.bad()) << VV(f.fail()) << VV(size);
f.close();
}

Expand Down

0 comments on commit 81403f3

Please sign in to comment.