Skip to content

Commit

Permalink
Remove usages of tsl::Status::error_message.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 525367359
  • Loading branch information
jblespiau authored and tensorflow-copybara committed Apr 19, 2023
1 parent 4808c01 commit 34773c3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
23 changes: 23 additions & 0 deletions research/carls/base/file_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ limitations under the License.

#include "research/carls/base/file_helper.h"

#include <string>

#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 {
Expand Down Expand Up @@ -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<const char*>(file->data()), file->length());
return absl::OkStatus();
Expand All @@ -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();
}
Expand Down
7 changes: 7 additions & 0 deletions research/carls/base/status_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ limitations under the License.

#include "research/carls/base/status_helper.h"

#include <string>

#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 <dlfcn.h>
Expand Down Expand Up @@ -214,7 +217,11 @@ absl::Status ToAbslStatus(const grpc::Status& status) {

absl::Status ToAbslStatus(const tensorflow::Status& status) {
return absl::Status(static_cast<absl::StatusCode>(status.code()),
#if TF_GRAPH_DEF_VERSION < 1467
status.error_message());
#else
status.message());
#endif
}

grpc::Status ToGrpcStatus(const absl::Status& status) {
Expand Down
10 changes: 10 additions & 0 deletions research/carls/testing/test_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ limitations under the License.

#include "research/carls/testing/test_helper.h"

#include <string>

#include "grpcpp/support/status.h" // net
#include "tensorflow/core/platform/status.h"
#include "tensorflow/core/public/version.h"

namespace carls {
namespace internal {
Expand All @@ -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
Expand Down

0 comments on commit 34773c3

Please sign in to comment.