Skip to content

Commit 34773c3

Browse files
jblespiautensorflow-copybara
authored andcommitted
Remove usages of tsl::Status::error_message.
PiperOrigin-RevId: 525367359
1 parent 4808c01 commit 34773c3

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

research/carls/base/file_helper.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ limitations under the License.
1515

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

18+
#include <string>
19+
1820
#include "absl/status/status.h"
1921
#include "absl/strings/string_view.h"
2022
#include "research/carls/base/status_helper.h"
2123
#include "tensorflow/core/platform/env.h"
24+
#include "tensorflow/core/public/version.h"
2225

2326
namespace carls {
2427
namespace internal {
@@ -66,8 +69,13 @@ absl::Status ReadFileString(const std::string& filepath, std::string* output) {
6669
auto tf_status = env->NewReadOnlyMemoryRegionFromFile(filepath, &file);
6770
if (!tf_status.ok()) {
6871
return absl::Status(absl::StatusCode::kInternal,
72+
#if TF_GRAPH_DEF_VERSION < 1467
6973
absl::StrCat("Reading file failed with error:",
7074
tf_status.error_message()));
75+
#else
76+
absl::StrCat("Reading file failed with error:",
77+
tf_status.message()));
78+
#endif
7179
}
7280
*output = std::string(static_cast<const char*>(file->data()), file->length());
7381
return absl::OkStatus();
@@ -84,20 +92,35 @@ absl::Status WriteFileString(const std::string& filepath,
8492
auto tf_status = env->NewWritableFile(filepath, &file);
8593
if (!tf_status.ok()) {
8694
return absl::Status(absl::StatusCode::kInternal,
95+
#if TF_GRAPH_DEF_VERSION < 1467
8796
absl::StrCat("Creating file failed with error:",
8897
tf_status.error_message()));
98+
#else
99+
absl::StrCat("Creating file failed with error:",
100+
tf_status.message()));
101+
#endif
89102
}
90103
tf_status = file->Append(content);
91104
if (!tf_status.ok()) {
92105
return absl::Status(absl::StatusCode::kInternal,
106+
#if TF_GRAPH_DEF_VERSION < 1467
93107
absl::StrCat("Appending file failed with error:",
94108
tf_status.error_message()));
109+
#else
110+
absl::StrCat("Appending file failed with error:",
111+
tf_status.message()));
112+
#endif
95113
}
96114
tf_status = file->Close();
97115
if (!tf_status.ok()) {
98116
return absl::Status(absl::StatusCode::kInternal,
117+
#if TF_GRAPH_DEF_VERSION < 1467
99118
absl::StrCat("Closing file failed with error:",
100119
tf_status.error_message()));
120+
#else
121+
absl::StrCat("Closing file failed with error:",
122+
tf_status.message()));
123+
#endif
101124
}
102125
return absl::OkStatus();
103126
}

research/carls/base/status_helper.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ limitations under the License.
1515

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

18+
#include <string>
19+
1820
#include "absl/status/status.h"
1921
#include "absl/strings/str_cat.h"
2022
#include "tensorflow/core/platform/abi.h"
23+
#include "tensorflow/core/public/version.h"
2124

2225
#if defined(TF_HAS_STACKTRACE)
2326
#include <dlfcn.h>
@@ -214,7 +217,11 @@ absl::Status ToAbslStatus(const grpc::Status& status) {
214217

215218
absl::Status ToAbslStatus(const tensorflow::Status& status) {
216219
return absl::Status(static_cast<absl::StatusCode>(status.code()),
220+
#if TF_GRAPH_DEF_VERSION < 1467
217221
status.error_message());
222+
#else
223+
status.message());
224+
#endif
218225
}
219226

220227
grpc::Status ToGrpcStatus(const absl::Status& status) {

research/carls/testing/test_helper.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ limitations under the License.
1515

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

18+
#include <string>
19+
1820
#include "grpcpp/support/status.h" // net
1921
#include "tensorflow/core/platform/status.h"
22+
#include "tensorflow/core/public/version.h"
2023

2124
namespace carls {
2225
namespace internal {
@@ -33,7 +36,14 @@ std::string GetErrorMessage(const grpc::Status& status) {
3336

3437
template <>
3538
std::string GetErrorMessage(const tensorflow::Status& status) {
39+
// On April 2023, there is not yet an official release of Tensorflow which
40+
// includes `message().` One will need to wait for the release following 2.12.0.
41+
// The code can be updated to just be the else branch after such release exists.
42+
#if TF_GRAPH_DEF_VERSION < 1467
3643
return status.error_message();
44+
#else
45+
return std::string(status.message());
46+
#endif
3747
}
3848

3949
} // namespace internal

0 commit comments

Comments
 (0)