diff --git a/research/carls/base/file_helper.cc b/research/carls/base/file_helper.cc index 43a542a..20876db 100644 --- a/research/carls/base/file_helper.cc +++ b/research/carls/base/file_helper.cc @@ -15,10 +15,13 @@ limitations under the License. #include "research/carls/base/file_helper.h" +#include + #include "absl/status/status.h" #include "absl/strings/string_view.h" #include "research/carls/base/status_helper.h" #include "tensorflow/core/platform/env.h" +#include "tensorflow/core/public/version.h" namespace carls { namespace internal { @@ -66,8 +69,13 @@ absl::Status ReadFileString(const std::string& filepath, std::string* output) { auto tf_status = env->NewReadOnlyMemoryRegionFromFile(filepath, &file); if (!tf_status.ok()) { return absl::Status(absl::StatusCode::kInternal, +#if TF_GRAPH_DEF_VERSION < 1467 absl::StrCat("Reading file failed with error:", tf_status.error_message())); +#else + absl::StrCat("Reading file failed with error:", + tf_status.message())); +#endif } *output = std::string(static_cast(file->data()), file->length()); return absl::OkStatus(); @@ -84,20 +92,35 @@ absl::Status WriteFileString(const std::string& filepath, auto tf_status = env->NewWritableFile(filepath, &file); if (!tf_status.ok()) { return absl::Status(absl::StatusCode::kInternal, +#if TF_GRAPH_DEF_VERSION < 1467 absl::StrCat("Creating file failed with error:", tf_status.error_message())); +#else + absl::StrCat("Creating file failed with error:", + tf_status.message())); +#endif } tf_status = file->Append(content); if (!tf_status.ok()) { return absl::Status(absl::StatusCode::kInternal, +#if TF_GRAPH_DEF_VERSION < 1467 absl::StrCat("Appending file failed with error:", tf_status.error_message())); +#else + absl::StrCat("Appending file failed with error:", + tf_status.message())); +#endif } tf_status = file->Close(); if (!tf_status.ok()) { return absl::Status(absl::StatusCode::kInternal, +#if TF_GRAPH_DEF_VERSION < 1467 absl::StrCat("Closing file failed with error:", tf_status.error_message())); +#else + absl::StrCat("Closing file failed with error:", + tf_status.message())); +#endif } return absl::OkStatus(); } diff --git a/research/carls/base/status_helper.cc b/research/carls/base/status_helper.cc index 0a26091..1ecdfb5 100644 --- a/research/carls/base/status_helper.cc +++ b/research/carls/base/status_helper.cc @@ -15,9 +15,12 @@ limitations under the License. #include "research/carls/base/status_helper.h" +#include + #include "absl/status/status.h" #include "absl/strings/str_cat.h" #include "tensorflow/core/platform/abi.h" +#include "tensorflow/core/public/version.h" #if defined(TF_HAS_STACKTRACE) #include @@ -214,7 +217,11 @@ absl::Status ToAbslStatus(const grpc::Status& status) { absl::Status ToAbslStatus(const tensorflow::Status& status) { return absl::Status(static_cast(status.code()), +#if TF_GRAPH_DEF_VERSION < 1467 status.error_message()); +#else + status.message()); +#endif } grpc::Status ToGrpcStatus(const absl::Status& status) { diff --git a/research/carls/testing/test_helper.cc b/research/carls/testing/test_helper.cc index f39cf71..9386f2d 100644 --- a/research/carls/testing/test_helper.cc +++ b/research/carls/testing/test_helper.cc @@ -15,8 +15,11 @@ limitations under the License. #include "research/carls/testing/test_helper.h" +#include + #include "grpcpp/support/status.h" // net #include "tensorflow/core/platform/status.h" +#include "tensorflow/core/public/version.h" namespace carls { namespace internal { @@ -33,7 +36,14 @@ std::string GetErrorMessage(const grpc::Status& status) { template <> std::string GetErrorMessage(const tensorflow::Status& status) { +// On April 2023, there is not yet an official release of Tensorflow which +// includes `message().` One will need to wait for the release following 2.12.0. +// The code can be updated to just be the else branch after such release exists. +#if TF_GRAPH_DEF_VERSION < 1467 return status.error_message(); +#else + return std::string(status.message()); +#endif } } // namespace internal