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 #ifndef TENSORFLOW_CORE_DISTRIBUTED_RUNTIME_COORDINATION_COORDINATION_SERVICE_ERROR_H_
16 #define TENSORFLOW_CORE_DISTRIBUTED_RUNTIME_COORDINATION_COORDINATION_SERVICE_ERROR_H_
17
18 #include "absl/strings/string_view.h"
19 #include "tensorflow/core/platform/errors.h"
20 #include "tensorflow/core/platform/status.h"
21 #include "tensorflow/core/protobuf/coordination_service.pb.h"
22
23 namespace tensorflow {
24
CoordinationErrorPayloadKey()25 constexpr absl::string_view CoordinationErrorPayloadKey() {
26 return "type.googleapis.com/tensorflow.CoordinationServiceError";
27 }
28
29 // Mark error as a coordination service error (as opposed to RPC
30 // errors).
MakeCoordinationError(Status s)31 inline Status MakeCoordinationError(Status s) {
32 s.SetPayload(CoordinationErrorPayloadKey(), "");
33 return s;
34 }
35
36 // Mark error as a coordination service error (as opposed to RPC
37 // errors), and indicate error origin.
38 // Errors reported via the agent API by the user should set `is_reported_error`
39 // to true.
40 inline Status MakeCoordinationError(Status s, const CoordinatedTask& origin,
41 bool is_reported_error = false) {
42 CoordinationServiceError error;
43 *error.mutable_source_task() = origin;
44 error.set_is_reported_error(is_reported_error);
45 s.SetPayload(CoordinationErrorPayloadKey(), error.SerializeAsString());
46 return s;
47 }
48
49 // Mark error as a coordination service error with payload.
MakeCoordinationError(Status s,const CoordinationServiceError & payload)50 inline Status MakeCoordinationError(Status s,
51 const CoordinationServiceError& payload) {
52 s.SetPayload(CoordinationErrorPayloadKey(), payload.SerializeAsString());
53 return s;
54 }
55 } // namespace tensorflow
56
57 #endif // TENSORFLOW_CORE_DISTRIBUTED_RUNTIME_COORDINATION_COORDINATION_SERVICE_ERROR_H_
58