Skip to content

Commit 12e6e96

Browse files
loisloGoogle-ML-Automation
authored andcommitted
[XLA:GPU] Migrate from tsl::errors to absl::Status error creation functions.
This change replaces calls to `tsl::errors::FailedPrecondition`, `tsl::errors::Unavailable`, `tsl::errors::Internal`, and `tsl::errors::Aborted` with their equivalent `absl::FailedPreconditionError`, `absl::UnavailableError`, `absl::InternalError`, and `absl::AbortedError` functions. PiperOrigin-RevId: 839243361
1 parent b3c7b9c commit 12e6e96

File tree

9 files changed

+43
-36
lines changed

9 files changed

+43
-36
lines changed

xla/hlo/evaluator/hlo_evaluator.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3675,7 +3675,7 @@ absl::StatusOr<Literal> TryParseAndEvaluateWhileInductionVar(
36753675
std::optional<ParsedWhileLoop> parsed_while_loop =
36763676
PatternMatchParseWhileLoop(while_hlo, /*precomputed_analyses=*/{});
36773677
if (!parsed_while_loop.has_value() || parsed_while_loop->is_dynamic()) {
3678-
return FailedPrecondition(
3678+
return absl::FailedPreconditionError(
36793679
"Cannot evaluate a while loop's induction variable since the loop "
36803680
"does not match a known loop pattern or the loop is not static.");
36813681
}

xla/tsl/platform/cloud/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ cc_library(
357357
"//xla/tsl/platform:errors",
358358
"//xla/tsl/platform:status",
359359
"@boringssl//:crypto",
360+
"@com_google_absl//absl/status",
360361
"@jsoncpp_git//:jsoncpp",
361362
"@tsl//tsl/platform:base64",
362363
],

xla/tsl/platform/cloud/gcs_file_system_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ TEST(GcsFileSystemTest, NewRandomAccessFile_Buffered_Errors) {
181181
"Auth Token: fake_token\n"
182182
"Range: 0-9\n"
183183
"Timeouts: 5 1 20\n",
184-
"Server Not", errors::Unavailable("important HTTP error 308"),
184+
"Server Not", absl::UnavailableError("important HTTP error 308"),
185185
nullptr, {}, 308),
186186
new FakeHttpRequest(
187187
"Uri: https://storage.googleapis.com/bucket/random_access.txt\n"
@@ -1127,7 +1127,7 @@ TEST(GcsFileSystemTest, NewWritableFile_ResumeUploadSucceedsOnGetStatus) {
11271127
"Header Content-Range: bytes 0-16/17\n"
11281128
"Timeouts: 5 1 30\n"
11291129
"Put body: content1,content2\n",
1130-
"", errors::Unavailable("503"), 503),
1130+
"", absl::UnavailableError("503"), 503),
11311131
new FakeHttpRequest("Uri: https://custom/upload/location\n"
11321132
"Auth Token: fake_token\n"
11331133
"Timeouts: 5 1 10\n"

xla/tsl/platform/cloud/google_auth_provider.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ absl::Status GetWellKnownFileName(string* filename) {
120120
// Determine the home dir path.
121121
const char* home_dir = std::getenv("HOME");
122122
if (!home_dir) {
123-
return errors::FailedPrecondition("Could not read $HOME.");
123+
return absl::FailedPreconditionError("Could not read $HOME.");
124124
}
125125
config_dir = io::JoinPath(home_dir, kGCloudConfigFolder);
126126
}
@@ -240,7 +240,7 @@ absl::Status GoogleAuthProvider::GetTokenFromFiles() {
240240
json, kOAuthV4Url, kOAuthScope, &current_token_,
241241
&expiration_timestamp_sec_));
242242
} else {
243-
return errors::FailedPrecondition(
243+
return absl::FailedPreconditionError(
244244
"Unexpected content of the JSON credentials file.");
245245
}
246246
return absl::OkStatus();

xla/tsl/platform/cloud/oauth_client.cc

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ limitations under the License.
1414
==============================================================================*/
1515

1616
#include "xla/tsl/platform/cloud/oauth_client.h"
17+
18+
#include "absl/status/status.h"
1719
#ifndef _WIN32
1820
#include <pwd.h>
1921
#include <sys/types.h>
@@ -94,7 +96,7 @@ absl::Status CreateSignature(RSA* private_key, absl::string_view to_sign,
9496

9597
const auto md = EVP_sha256();
9698
if (!md) {
97-
return errors::Internal("Could not get a sha256 encryptor.");
99+
return absl::InternalError("Could not get a sha256 encryptor.");
98100
}
99101

100102
// EVP_MD_CTX_destroy is renamed to EVP_MD_CTX_free in OpenSSL 1.1.0 but
@@ -104,26 +106,26 @@ absl::Status CreateSignature(RSA* private_key, absl::string_view to_sign,
104106
std::unique_ptr<EVP_MD_CTX, std::function<void(EVP_MD_CTX*)>> md_ctx(
105107
EVP_MD_CTX_create(), [](EVP_MD_CTX* ptr) { EVP_MD_CTX_destroy(ptr); });
106108
if (!md_ctx) {
107-
return errors::Internal("Could not create MD_CTX.");
109+
return absl::InternalError("Could not create MD_CTX.");
108110
}
109111

110112
std::unique_ptr<EVP_PKEY, std::function<void(EVP_PKEY*)>> key(
111113
EVP_PKEY_new(), [](EVP_PKEY* ptr) { EVP_PKEY_free(ptr); });
112114
EVP_PKEY_set1_RSA(key.get(), private_key);
113115

114116
if (EVP_DigestSignInit(md_ctx.get(), nullptr, md, nullptr, key.get()) != 1) {
115-
return errors::Internal("DigestInit failed.");
117+
return absl::InternalError("DigestInit failed.");
116118
}
117119
if (EVP_DigestSignUpdate(md_ctx.get(), to_sign.data(), to_sign.size()) != 1) {
118-
return errors::Internal("DigestUpdate failed.");
120+
return absl::InternalError("DigestUpdate failed.");
119121
}
120122
size_t sig_len = 0;
121123
if (EVP_DigestSignFinal(md_ctx.get(), nullptr, &sig_len) != 1) {
122-
return errors::Internal("DigestFinal (get signature length) failed.");
124+
return absl::InternalError("DigestFinal (get signature length) failed.");
123125
}
124126
std::unique_ptr<unsigned char[]> sig(new unsigned char[sig_len]);
125127
if (EVP_DigestSignFinal(md_ctx.get(), sig.get(), &sig_len) != 1) {
126-
return errors::Internal("DigestFinal (signature compute) failed.");
128+
return absl::InternalError("DigestFinal (signature compute) failed.");
127129
}
128130
return Base64Encode(
129131
absl::string_view(reinterpret_cast<char*>(sig.get()), sig_len),
@@ -198,13 +200,13 @@ absl::Status OAuthClient::GetTokenFromServiceAccountJson(
198200
BIO_new(BIO_s_mem()), [](BIO* ptr) { BIO_free_all(ptr); });
199201
if (BIO_puts(bio.get(), private_key_serialized.c_str()) !=
200202
static_cast<int>(private_key_serialized.size())) {
201-
return errors::Internal("Could not load the private key.");
203+
return absl::InternalError("Could not load the private key.");
202204
}
203205
std::unique_ptr<RSA, std::function<void(RSA*)>> private_key(
204206
PEM_read_bio_RSAPrivateKey(bio.get(), nullptr, nullptr, nullptr),
205207
[](RSA* ptr) { RSA_free(ptr); });
206208
if (!private_key) {
207-
return errors::Internal("Could not deserialize the private key.");
209+
return absl::InternalError("Could not deserialize the private key.");
208210
}
209211

210212
const uint64 request_timestamp_sec = env_->NowSeconds();
@@ -278,14 +280,15 @@ absl::Status OAuthClient::ParseOAuthResponse(absl::string_view response,
278280
Json::Value root;
279281
Json::Reader reader;
280282
if (!reader.parse(response.data(), response.data() + response.size(), root)) {
281-
return errors::Internal("Couldn't parse JSON response from OAuth server.");
283+
return absl::InternalError(
284+
"Couldn't parse JSON response from OAuth server.");
282285
}
283286

284287
string token_type;
285288
TF_RETURN_IF_ERROR(ReadJsonString(root, "token_type", &token_type));
286289
if (token_type != "Bearer") {
287-
return errors::FailedPrecondition("Unexpected Oauth token type: " +
288-
token_type);
290+
return absl::FailedPreconditionError("Unexpected Oauth token type: " +
291+
token_type);
289292
}
290293
int64_t expires_in = 0;
291294
TF_RETURN_IF_ERROR(ReadJsonInt(root, "expires_in", &expires_in));

xla/tsl/platform/default/human_readable_json.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ absl::StatusOr<std::string> ProtoToHumanReadableJson(
4040
// Convert error_msg google::protobuf::StringPiece to
4141
// tsl::StringPiece.
4242
auto error_msg = status.message();
43-
return errors::Internal(
43+
return absl::InternalError(
4444
absl::StrCat("Could not convert proto to JSON string: ", error_msg));
4545
}
4646
return std::move(result);
@@ -59,15 +59,15 @@ absl::Status HumanReadableJsonToProto(const std::string& str,
5959
// Convert error_msg google::protobuf::StringPiece to
6060
// tsl::StringPiece.
6161
auto error_msg = status.message();
62-
return errors::Internal(
62+
return absl::InternalError(
6363
absl::StrCat("Could not convert JSON string to proto: ", error_msg));
6464
}
6565
return absl::OkStatus();
6666
}
6767

6868
absl::Status HumanReadableJsonToProto(const std::string& str,
6969
protobuf::MessageLite* proto) {
70-
return errors::Internal("Cannot parse JSON protos on Android");
70+
return absl::InternalError("Cannot parse JSON protos on Android");
7171
}
7272

7373
} // namespace tsl

xla/tsl/platform/env.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,9 @@ absl::Status ReadFileToString(Env* env, const std::string& fname,
504504
if (!s.ok()) {
505505
data->clear();
506506
} else if (result.size() != file_size) {
507-
s = errors::Aborted("File ", fname, " changed while reading: ", file_size,
508-
" vs. ", result.size());
507+
s = absl::AbortedError(absl::StrCat("File ", fname,
508+
" changed while reading: ", file_size,
509+
" vs. ", result.size()));
509510
data->clear();
510511
} else if (result.data() == p) {
511512
// Data is already in the correct location

xla/tsl/platform/errors_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ limitations under the License.
2121
namespace tsl {
2222

2323
TEST(AppendToMessageTest, PayloadsAreCopied) {
24-
absl::Status status = errors::Aborted("Aborted Error Message");
24+
absl::Status status = absl::AbortedError("Aborted Error Message");
2525
status.SetPayload("payload_key", absl::Cord("payload_value"));
2626
errors::AppendToMessage(&status, "Appended Message");
2727

xla/tsl/platform/status_test.cc

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
21
/* Copyright 2021 The TensorFlow Authors. All Rights Reserved.
2+
33
Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.
55
You may obtain a copy of the License at
6+
67
http://www.apache.org/licenses/LICENSE-2.0
8+
79
Unless required by applicable law or agreed to in writing, software
810
distributed under the License is distributed on an "AS IS" BASIS,
911
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -37,7 +39,7 @@ using ::testing::IsEmpty;
3739
using ::testing::Pair;
3840

3941
TEST(ToStringTest, PayloadsArePrinted) {
40-
absl::Status status = errors::Aborted("Aborted Error Message");
42+
absl::Status status = absl::AbortedError("Aborted Error Message");
4143
status.SetPayload("payload_key", absl::Cord(absl::StrFormat(
4244
"payload_value %c%c%c", 1, 2, 3)));
4345

@@ -47,7 +49,7 @@ TEST(ToStringTest, PayloadsArePrinted) {
4749
}
4850

4951
TEST(ToStringTest, MatchesAbslStatus) {
50-
absl::Status status = errors::Aborted("Aborted Error Message");
52+
absl::Status status = absl::AbortedError("Aborted Error Message");
5153
status.SetPayload("payload_key", absl::Cord(absl::StrFormat(
5254
"payload_value %c%c%c", 1, 2, 3)));
5355

@@ -60,7 +62,7 @@ TEST(ToStringTest, MatchesAbslStatus) {
6062
}
6163

6264
TEST(StackTrace, SerializeAndDeserializeCorrectly) {
63-
absl::Status status = errors::Aborted("Aborted Error Message");
65+
absl::Status status = absl::AbortedError("Aborted Error Message");
6466
std::vector<StackFrame> stack_trace;
6567
stack_trace.push_back(StackFrame("filename_1", 33, "func_name_1"));
6668
stack_trace.push_back(StackFrame("filename_2", 66, "func_name_2"));
@@ -75,9 +77,9 @@ TEST(StackTrace, SerializeAndDeserializeCorrectly) {
7577
}
7678

7779
TEST(StatusGroupTest, DeterministicOrderWithoutPayloads) {
78-
absl::Status status_a = errors::Aborted("Status A");
79-
absl::Status status_b = errors::Aborted("Status B");
80-
absl::Status status_c = errors::Aborted("Status C");
80+
absl::Status status_a = absl::AbortedError("Status A");
81+
absl::Status status_b = absl::AbortedError("Status B");
82+
absl::Status status_c = absl::AbortedError("Status C");
8183

8284
absl::Status combined =
8385
StatusGroup({status_a, status_b, status_c}).as_summary_status();
@@ -97,11 +99,11 @@ TEST(StatusGroupTest, DeterministicOrderWithoutPayloads) {
9799
}
98100

99101
TEST(StatusGroupTest, DeterministicOrderWithPayloads) {
100-
absl::Status status_a = errors::Aborted("Status A");
102+
absl::Status status_a = absl::AbortedError("Status A");
101103
status_a.SetPayload("payload_key", absl::Cord("payload_value_a"));
102-
absl::Status status_b = errors::Aborted("Status B");
104+
absl::Status status_b = absl::AbortedError("Status B");
103105
status_b.SetPayload("payload_key", absl::Cord("payload_value_b"));
104-
absl::Status status_c = errors::Aborted("Status C");
106+
absl::Status status_c = absl::AbortedError("Status C");
105107
status_c.SetPayload("payload_key", absl::Cord("payload_value_c"));
106108

107109
absl::Status combined =
@@ -130,17 +132,17 @@ TEST(StatusGroupTest, DeterministicOrderWithPayloads) {
130132
}
131133

132134
TEST(StatusGroupTest, PayloadsMergedProperly) {
133-
absl::Status status_a = errors::Aborted("Status A");
135+
absl::Status status_a = absl::AbortedError("Status A");
134136
status_a.SetPayload("payload_key_a",
135137
absl::Cord(std::string("payload_value_a")));
136-
absl::Status status_b = errors::Aborted("Status B");
138+
absl::Status status_b = absl::AbortedError("Status B");
137139
status_b.SetPayload("payload_key_b",
138140
absl::Cord(std::string("payload_value_b")));
139-
absl::Status status_c = errors::Aborted("Status C");
141+
absl::Status status_c = absl::AbortedError("Status C");
140142
status_c.SetPayload("payload_key_c",
141143
absl::Cord(std::string("payload_value_c")));
142144
absl::Status derived_status_c =
143-
StatusGroup::MakeDerived(errors::Aborted("Status C"));
145+
StatusGroup::MakeDerived(absl::AbortedError("Status C"));
144146
derived_status_c.SetPayload(
145147
"payload_key_c", absl::Cord(std::string("derived_payload_value_c")));
146148

0 commit comments

Comments
 (0)