Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions tsl/platform/base64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ absl::Status DecodeThreeChars(const char* codes, char* result) {
// Convert() return value has upper 25 bits set if input is invalid.
// Therefore `packed` has high bits set iff at least one of code is invalid.
if (TF_PREDICT_FALSE((packed & 0xFF000000) != 0)) {
return errors::InvalidArgument("Invalid character found in base64.");
return absl::InvalidArgumentError("Invalid character found in base64.");
}
result[0] = static_cast<char>(packed >> 16);
result[1] = static_cast<char>(packed >> 8);
Expand All @@ -82,7 +82,7 @@ absl::Status DecodeThreeChars(const char* codes, char* result) {
template <typename T>
absl::Status Base64Decode(absl::string_view data, T* decoded) {
if (decoded == nullptr) {
return errors::Internal("'decoded' cannot be nullptr.");
return absl::InternalError("'decoded' cannot be nullptr.");
}

if (data.empty()) {
Expand All @@ -98,7 +98,7 @@ absl::Status Base64Decode(absl::string_view data, T* decoded) {
std::unique_ptr<char[]> buffer(new char[max_decoded_size]);
char* current = buffer.get();
if (current == nullptr) {
return errors::ResourceExhausted(
return absl::ResourceExhaustedError(
"Failed to allocate buffer for decoded string.");
}

Expand All @@ -125,7 +125,7 @@ absl::Status Base64Decode(absl::string_view data, T* decoded) {
const int remain = static_cast<int>(end - b64);
if (TF_PREDICT_FALSE(remain == 1)) {
// We may check this condition early by checking data.size() % 4 == 1.
return errors::InvalidArgument(
return absl::InvalidArgumentError(
"Base64 string length cannot be 1 modulo 4.");
}

Expand All @@ -152,15 +152,15 @@ absl::Status Base64Encode(absl::string_view source, bool with_padding,
T* encoded) {
const char* const base64_chars = kBase64UrlSafeChars;
if (encoded == nullptr) {
return errors::Internal("'encoded' cannot be nullptr.");
return absl::InternalError("'encoded' cannot be nullptr.");
}

// max_encoded_size may overestimate by up to 4 bytes.
const size_t max_encoded_size = 4 * (source.size() / 3) + 4;
std::unique_ptr<char[]> buffer(new char[max_encoded_size]);
char* current = buffer.get();
if (current == nullptr) {
return errors::ResourceExhausted(
return absl::ResourceExhaustedError(
"Failed to allocate buffer for encoded string.");
}

Expand Down
24 changes: 12 additions & 12 deletions tsl/platform/null_file_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,34 @@ class NullFileSystem : public FileSystem {
absl::Status NewRandomAccessFile(
const std::string& fname,
std::unique_ptr<RandomAccessFile>* result) override {
return errors::Unimplemented("NewRandomAccessFile unimplemented");
return absl::UnimplementedError("NewRandomAccessFile unimplemented");
}

absl::Status NewWritableFile(const std::string& fname,
std::unique_ptr<WritableFile>* result) override {
return errors::Unimplemented("NewWritableFile unimplemented");
return absl::UnimplementedError("NewWritableFile unimplemented");
}

absl::Status NewAppendableFile(
const std::string& fname,
std::unique_ptr<WritableFile>* result) override {
return errors::Unimplemented("NewAppendableFile unimplemented");
return absl::UnimplementedError("NewAppendableFile unimplemented");
}

absl::Status NewReadOnlyMemoryRegionFromFile(
const std::string& fname,
std::unique_ptr<ReadOnlyMemoryRegion>* result) override {
return errors::Unimplemented(
return absl::UnimplementedError(
"NewReadOnlyMemoryRegionFromFile unimplemented");
}

absl::Status FileExists(absl::string_view fname) override {
return errors::Unimplemented("FileExists unimplemented");
return absl::UnimplementedError("FileExists unimplemented");
}

absl::Status GetChildren(const std::string& dir,
std::vector<std::string>* result) override {
return errors::Unimplemented("GetChildren unimplemented");
return absl::UnimplementedError("GetChildren unimplemented");
}

absl::Status GetMatchingPaths(const std::string& pattern,
Expand All @@ -77,29 +77,29 @@ class NullFileSystem : public FileSystem {
}

absl::Status DeleteFile(const std::string& fname) override {
return errors::Unimplemented("DeleteFile unimplemented");
return absl::UnimplementedError("DeleteFile unimplemented");
}

absl::Status CreateDir(const std::string& dirname) override {
return errors::Unimplemented("CreateDir unimplemented");
return absl::UnimplementedError("CreateDir unimplemented");
}

absl::Status DeleteDir(const std::string& dirname) override {
return errors::Unimplemented("DeleteDir unimplemented");
return absl::UnimplementedError("DeleteDir unimplemented");
}

absl::Status GetFileSize(const std::string& fname,
uint64_t* file_size) override {
return errors::Unimplemented("GetFileSize unimplemented");
return absl::UnimplementedError("GetFileSize unimplemented");
}

absl::Status RenameFile(const std::string& src,
const std::string& target) override {
return errors::Unimplemented("RenameFile unimplemented");
return absl::UnimplementedError("RenameFile unimplemented");
}

absl::Status Stat(const std::string& fname, FileStatistics* stat) override {
return errors::Unimplemented("Stat unimplemented");
return absl::UnimplementedError("Stat unimplemented");
}
};
#endif
Expand Down
51 changes: 29 additions & 22 deletions tsl/platform/retrying_file_system_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ ExpectedCalls CreateRetriableErrors(const std::string& method, int n) {
expected_calls.reserve(n);
for (int i = 0; i < n; i++) {
expected_calls.emplace_back(std::make_tuple(
method, errors::Unavailable(absl::StrCat("Retriable error #", i))));
method, absl::UnavailableError(absl::StrCat("Retriable error #", i))));
}
return expected_calls;
}
Expand Down Expand Up @@ -234,8 +234,8 @@ TEST(RetryingFileSystemTest, NewRandomAccessFile_ImmediateSuccess) {
TEST(RetryingFileSystemTest, NewRandomAccessFile_SuccessWith3rdTry) {
// Configure the mock base random access file.
ExpectedCalls expected_file_calls(
{std::make_tuple("Read", errors::Unavailable("Something is wrong")),
std::make_tuple("Read", errors::Unavailable("Wrong again")),
{std::make_tuple("Read", absl::UnavailableError("Something is wrong")),
std::make_tuple("Read", absl::UnavailableError("Wrong again")),
std::make_tuple("Read", absl::OkStatus())});
std::unique_ptr<RandomAccessFile> base_file(
new MockRandomAccessFile(expected_file_calls));
Expand Down Expand Up @@ -292,7 +292,7 @@ TEST(RetryingFileSystemTest, NewRandomAccessFile_NoRetriesForSomeErrors) {
// Configure the mock base random access file.
ExpectedCalls expected_file_calls({
std::make_tuple("Read",
errors::FailedPrecondition("Failed precondition")),
absl::FailedPreconditionError("Failed precondition")),
});
std::unique_ptr<RandomAccessFile> base_file(
new MockRandomAccessFile(expected_file_calls));
Expand Down Expand Up @@ -351,8 +351,9 @@ TEST(RetryingFileSystemTest, NewWritableFile_ImmediateSuccess) {
TEST(RetryingFileSystemTest, NewWritableFile_SuccessWith3rdTry) {
// Configure the mock base random access file.
ExpectedCalls expected_file_calls(
{std::make_tuple("Sync", errors::Unavailable("Something is wrong")),
std::make_tuple("Sync", errors::Unavailable("Something is wrong again")),
{std::make_tuple("Sync", absl::UnavailableError("Something is wrong")),
std::make_tuple("Sync",
absl::UnavailableError("Something is wrong again")),
std::make_tuple("Sync", absl::OkStatus()),
std::make_tuple("Close", absl::OkStatus())});
std::unique_ptr<WritableFile> base_file(
Expand All @@ -378,9 +379,9 @@ TEST(RetryingFileSystemTest, NewWritableFile_SuccessWith3rdTry) {
TEST(RetryingFileSystemTest, NewWritableFile_SuccessWith3rdTry_ViaDestructor) {
// Configure the mock base random access file.
ExpectedCalls expected_file_calls(
{std::make_tuple("Close", errors::Unavailable("Something is wrong")),
{std::make_tuple("Close", absl::UnavailableError("Something is wrong")),
std::make_tuple("Close",
errors::Unavailable("Something is wrong again")),
absl::UnavailableError("Something is wrong again")),
std::make_tuple("Close", absl::OkStatus())});
std::unique_ptr<WritableFile> base_file(
new MockWritableFile(expected_file_calls));
Expand All @@ -404,8 +405,9 @@ TEST(RetryingFileSystemTest, NewWritableFile_SuccessWith3rdTry_ViaDestructor) {
TEST(RetryingFileSystemTest, NewAppendableFile_SuccessWith3rdTry) {
// Configure the mock base random access file.
ExpectedCalls expected_file_calls(
{std::make_tuple("Sync", errors::Unavailable("Something is wrong")),
std::make_tuple("Sync", errors::Unavailable("Something is wrong again")),
{std::make_tuple("Sync", absl::UnavailableError("Something is wrong")),
std::make_tuple("Sync",
absl::UnavailableError("Something is wrong again")),
std::make_tuple("Sync", absl::OkStatus()),
std::make_tuple("Close", absl::OkStatus())});
std::unique_ptr<WritableFile> base_file(
Expand Down Expand Up @@ -458,7 +460,7 @@ TEST(RetryingFileSystemTest,
NewReadOnlyMemoryRegionFromFile_SuccessWith2ndTry) {
ExpectedCalls expected_fs_calls(
{std::make_tuple("NewReadOnlyMemoryRegionFromFile",
errors::Unavailable("Something is wrong")),
absl::UnavailableError("Something is wrong")),
std::make_tuple("NewReadOnlyMemoryRegionFromFile", absl::OkStatus())});
std::unique_ptr<MockFileSystem> base_fs(
new MockFileSystem(expected_fs_calls));
Expand Down Expand Up @@ -487,7 +489,7 @@ TEST(RetryingFileSystemTest, NewReadOnlyMemoryRegionFromFile_AllRetriesFailed) {
TEST(RetryingFileSystemTest, GetChildren_SuccessWith2ndTry) {
ExpectedCalls expected_fs_calls(
{std::make_tuple("GetChildren",
errors::Unavailable("Something is wrong")),
absl::UnavailableError("Something is wrong")),
std::make_tuple("GetChildren", absl::OkStatus())});
std::unique_ptr<MockFileSystem> base_fs(
new MockFileSystem(expected_fs_calls));
Expand All @@ -514,7 +516,7 @@ TEST(RetryingFileSystemTest, GetChildren_AllRetriesFailed) {
TEST(RetryingFileSystemTest, GetMatchingPaths_SuccessWith2ndTry) {
ExpectedCalls expected_fs_calls(
{std::make_tuple("GetMatchingPaths",
errors::Unavailable("Something is wrong")),
absl::UnavailableError("Something is wrong")),
std::make_tuple("GetMatchingPaths", absl::OkStatus())});
std::unique_ptr<MockFileSystem> base_fs(
new MockFileSystem(expected_fs_calls));
Expand All @@ -541,7 +543,8 @@ TEST(RetryingFileSystemTest, GetMatchingPaths_AllRetriesFailed) {

TEST(RetryingFileSystemTest, DeleteFile_SuccessWith2ndTry) {
ExpectedCalls expected_fs_calls(
{std::make_tuple("DeleteFile", errors::Unavailable("Something is wrong")),
{std::make_tuple("DeleteFile",
absl::UnavailableError("Something is wrong")),
std::make_tuple("DeleteFile", absl::OkStatus())});
std::unique_ptr<MockFileSystem> base_fs(
new MockFileSystem(expected_fs_calls));
Expand All @@ -565,7 +568,8 @@ TEST(RetryingFileSystemTest, DeleteFile_AllRetriesFailed) {

TEST(RetryingFileSystemTest, CreateDir_SuccessWith2ndTry) {
ExpectedCalls expected_fs_calls(
{std::make_tuple("CreateDir", errors::Unavailable("Something is wrong")),
{std::make_tuple("CreateDir",
absl::UnavailableError("Something is wrong")),
std::make_tuple("CreateDir", absl::OkStatus())});
std::unique_ptr<MockFileSystem> base_fs(
new MockFileSystem(expected_fs_calls));
Expand All @@ -589,7 +593,8 @@ TEST(RetryingFileSystemTest, CreateDir_AllRetriesFailed) {

TEST(RetryingFileSystemTest, DeleteDir_SuccessWith2ndTry) {
ExpectedCalls expected_fs_calls(
{std::make_tuple("DeleteDir", errors::Unavailable("Something is wrong")),
{std::make_tuple("DeleteDir",
absl::UnavailableError("Something is wrong")),
std::make_tuple("DeleteDir", absl::OkStatus())});
std::unique_ptr<MockFileSystem> base_fs(
new MockFileSystem(expected_fs_calls));
Expand All @@ -614,7 +619,7 @@ TEST(RetryingFileSystemTest, DeleteDir_AllRetriesFailed) {
TEST(RetryingFileSystemTest, GetFileSize_SuccessWith2ndTry) {
ExpectedCalls expected_fs_calls(
{std::make_tuple("GetFileSize",
errors::Unavailable("Something is wrong")),
absl::UnavailableError("Something is wrong")),
std::make_tuple("GetFileSize", absl::OkStatus())});
std::unique_ptr<MockFileSystem> base_fs(
new MockFileSystem(expected_fs_calls));
Expand All @@ -640,7 +645,8 @@ TEST(RetryingFileSystemTest, GetFileSize_AllRetriesFailed) {

TEST(RetryingFileSystemTest, RenameFile_SuccessWith2ndTry) {
ExpectedCalls expected_fs_calls(
{std::make_tuple("RenameFile", errors::Unavailable("Something is wrong")),
{std::make_tuple("RenameFile",
absl::UnavailableError("Something is wrong")),
std::make_tuple("RenameFile", absl::OkStatus())});
std::unique_ptr<MockFileSystem> base_fs(
new MockFileSystem(expected_fs_calls));
Expand All @@ -664,7 +670,7 @@ TEST(RetryingFileSystemTest, RenameFile_AllRetriesFailed) {

TEST(RetryingFileSystemTest, Stat_SuccessWith2ndTry) {
ExpectedCalls expected_fs_calls(
{std::make_tuple("Stat", errors::Unavailable("Something is wrong")),
{std::make_tuple("Stat", absl::UnavailableError("Something is wrong")),
std::make_tuple("Stat", absl::OkStatus())});
std::unique_ptr<MockFileSystem> base_fs(
new MockFileSystem(expected_fs_calls));
Expand Down Expand Up @@ -702,7 +708,8 @@ TEST(RetryingFileSystemTest, FileExists_AllRetriesFailed) {

TEST(RetryingFileSystemTest, FileExists_SuccessWith2ndTry) {
ExpectedCalls expected_fs_calls(
{std::make_tuple("FileExists", errors::Unavailable("Something is wrong")),
{std::make_tuple("FileExists",
absl::UnavailableError("Something is wrong")),
std::make_tuple("FileExists", absl::OkStatus())});
std::unique_ptr<MockFileSystem> base_fs(
new MockFileSystem(expected_fs_calls));
Expand All @@ -715,7 +722,7 @@ TEST(RetryingFileSystemTest, FileExists_SuccessWith2ndTry) {
TEST(RetryingFileSystemTest, IsDirectory_SuccessWith2ndTry) {
ExpectedCalls expected_fs_calls(
{std::make_tuple("IsDirectory",
errors::Unavailable("Something is wrong")),
absl::UnavailableError("Something is wrong")),
std::make_tuple("IsDirectory", absl::OkStatus())});
std::unique_ptr<MockFileSystem> base_fs(
new MockFileSystem(expected_fs_calls));
Expand All @@ -740,7 +747,7 @@ TEST(RetryingFileSystemTest, IsDirectory_AllRetriesFailed) {
TEST(RetryingFileSystemTest, DeleteRecursively_SuccessWith2ndTry) {
ExpectedCalls expected_fs_calls(
{std::make_tuple("DeleteRecursively",
errors::Unavailable("Something is wrong")),
absl::UnavailableError("Something is wrong")),
std::make_tuple("DeleteRecursively", absl::OkStatus())});
std::unique_ptr<MockFileSystem> base_fs(
new MockFileSystem(expected_fs_calls));
Expand Down
16 changes: 8 additions & 8 deletions tsl/platform/retrying_utils_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ TEST(RetryingUtilsTest, CallWithRetries_RetryDelays) {
requested_delays.emplace_back(delay / 1000000.0);
};
std::function<absl::Status()> f = []() {
return errors::Unavailable("Failed.");
return absl::UnavailableError("Failed.");
};

const auto& status = RetryingUtils::CallWithRetries(
Expand Down Expand Up @@ -65,7 +65,7 @@ TEST(RetryingUtilsTest, CallWithRetries_RetryDelays) {

TEST(RetryingUtilsTest, CallWithRetries_NotFoundIsNotRetried) {
std::vector<absl::Status> results(
{errors::Unavailable("Failed."), errors::NotFound("Not found.")});
{absl::UnavailableError("Failed."), absl::NotFoundError("Not found.")});
std::function<absl::Status()> f = [&results]() {
auto result = results[0];
results.erase(results.begin());
Expand All @@ -90,8 +90,8 @@ TEST(RetryingUtilsTest, CallWithRetries_ImmediateSuccess) {
}

TEST(RetryingUtilsTest, CallWithRetries_EventualSuccess) {
std::vector<absl::Status> results({errors::Unavailable("Failed."),
errors::Unavailable("Failed again."),
std::vector<absl::Status> results({absl::UnavailableError("Failed."),
absl::UnavailableError("Failed again."),
absl::OkStatus()});
std::function<absl::Status()> f = [&results]() {
auto result = results[0];
Expand All @@ -115,7 +115,7 @@ TEST(RetryingUtilsTest, DeleteWithRetries_ImmediateSuccess) {

TEST(RetryingUtilsTest, DeleteWithRetries_EventualSuccess) {
std::vector<absl::Status> delete_results(
{errors::Unavailable(""), absl::OkStatus()});
{absl::UnavailableError(""), absl::OkStatus()});
const auto delete_func = [&delete_results]() {
auto result = delete_results[0];
delete_results.erase(delete_results.begin());
Expand All @@ -127,7 +127,7 @@ TEST(RetryingUtilsTest, DeleteWithRetries_EventualSuccess) {

TEST(RetryingUtilsTest, DeleteWithRetries_PermissionDeniedNotRetried) {
std::vector<absl::Status> delete_results(
{errors::Unavailable(""), errors::PermissionDenied("")});
{absl::UnavailableError(""), absl::PermissionDeniedError("")});
const auto delete_func = [&delete_results]() {
auto result = delete_results[0];
delete_results.erase(delete_results.begin());
Expand All @@ -139,7 +139,7 @@ TEST(RetryingUtilsTest, DeleteWithRetries_PermissionDeniedNotRetried) {

TEST(RetryingUtilsTest, DeleteWithRetries_SuccessThroughFileNotFound) {
std::vector<absl::Status> delete_results(
{errors::Unavailable(""), errors::NotFound("")});
{absl::UnavailableError(""), absl::NotFoundError("")});
const auto delete_func = [&delete_results]() {
auto result = delete_results[0];
delete_results.erase(delete_results.begin());
Expand All @@ -150,7 +150,7 @@ TEST(RetryingUtilsTest, DeleteWithRetries_SuccessThroughFileNotFound) {
}

TEST(RetryingUtilsTest, DeleteWithRetries_FirstNotFoundReturnedAsIs) {
std::vector<absl::Status> delete_results({errors::NotFound("")});
std::vector<absl::Status> delete_results({absl::NotFoundError("")});
const auto delete_func = [&delete_results]() {
auto result = delete_results[0];
delete_results.erase(delete_results.begin());
Expand Down
Loading