File loading fix (#36071)

https://github.com/grpc/grpc/pull/35856 was delayed because the API involved was being removed in https://github.com/grpc/grpc/pull/35857

This PR is the work we discussed as followup in https://github.com/grpc/grpc/pull/35857
Namely, removing the assert that will crash grpc because of a file loading failure - we don't want this, and would rather just return an error (https://b.corp.google.com/issues/262285099, b/262240495

Closes #36071

COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/36071 from gtcooke94:file_loading_fix cc358fadce
PiperOrigin-RevId: 616895887
pull/36146/head
Gregory Cooke 11 months ago committed by Copybara-Service
parent b940f11388
commit 5b4bd43c78
  1. 4
      src/core/lib/gprpp/load_file.cc

@ -32,6 +32,9 @@ namespace grpc_core {
// Loads the content of a file into a slice. add_null_terminator will add a NULL
// terminator if true.
// This API is NOT thread-safe and requires proper synchronization when used by
// multiple threads, especially when they can happen to be reading from the same
// file.
absl::StatusOr<Slice> LoadFile(const std::string& filename,
bool add_null_terminator) {
unsigned char* contents = nullptr;
@ -61,7 +64,6 @@ absl::StatusOr<Slice> LoadFile(const std::string& filename,
bytes_read = fread(contents, 1, contents_size, file);
if (bytes_read < contents_size) {
gpr_free(contents);
GPR_ASSERT(ferror(file));
error = absl::InternalError(
absl::StrCat("Failed to load file: ", filename,
" due to error(fread): ", strerror(errno)));

Loading…
Cancel
Save