• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2022 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #include "tensorflow/core/tpu/tpu_embedding_errors.h"
17 
18 #include <string>
19 
20 #include "absl/strings/match.h"
21 
22 namespace tensorflow::tpu {
23 
AppendTpuEmbeddingErrorPayload(Status obj)24 Status AppendTpuEmbeddingErrorPayload(Status obj) {
25   if (obj.ok()) {
26     return OkStatus();
27   } else {
28     const std::string error_message =
29         absl::StrCat(kTpuEmbeddingErrorMessage, ". ", obj.error_message());
30     Status status(obj.code(), error_message);
31     TPUEmbeddingError error_payload;
32     status.SetPayload(kTpuEmbeddingErrorUrl, error_payload.SerializeAsString());
33     return status;
34   }
35 }
36 
HasTpuEmbeddingErrorPayload(const Status & status)37 bool HasTpuEmbeddingErrorPayload(const Status& status) {
38   return status.GetPayload(kTpuEmbeddingErrorUrl).has_value();
39 }
40 
HasTpuEmbeddingErrorMessage(const Status & status)41 bool HasTpuEmbeddingErrorMessage(const Status& status) {
42   return absl::StrContains(status.error_message(), kTpuEmbeddingErrorMessage);
43 }
44 
45 }  // namespace tensorflow::tpu
46