1 /* Copyright 2016 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/c/tf_status_helper.h"
17 #include "tensorflow/c/c_api_internal.h"
18
19 namespace tensorflow {
20
Set_TF_Status_from_Status(TF_Status * tf_status,const Status & status)21 void Set_TF_Status_from_Status(TF_Status* tf_status, const Status& status) {
22 tensorflow::error::Code code = status.code();
23 const char* message(status.error_message().c_str());
24
25 switch (code) {
26 case tensorflow::error::OK:
27 assert(TF_GetCode(tf_status) == TF_OK);
28 break;
29 case tensorflow::error::CANCELLED:
30 TF_SetStatus(tf_status, TF_CANCELLED, message);
31 break;
32 case tensorflow::error::UNKNOWN:
33 TF_SetStatus(tf_status, TF_UNKNOWN, message);
34 break;
35 case tensorflow::error::INVALID_ARGUMENT:
36 TF_SetStatus(tf_status, TF_INVALID_ARGUMENT, message);
37 break;
38 case tensorflow::error::DEADLINE_EXCEEDED:
39 TF_SetStatus(tf_status, TF_DEADLINE_EXCEEDED, message);
40 break;
41 case tensorflow::error::NOT_FOUND:
42 TF_SetStatus(tf_status, TF_NOT_FOUND, message);
43 break;
44 case tensorflow::error::ALREADY_EXISTS:
45 TF_SetStatus(tf_status, TF_ALREADY_EXISTS, message);
46 break;
47 case tensorflow::error::PERMISSION_DENIED:
48 TF_SetStatus(tf_status, TF_PERMISSION_DENIED, message);
49 break;
50 case tensorflow::error::UNAUTHENTICATED:
51 TF_SetStatus(tf_status, TF_UNAUTHENTICATED, message);
52 break;
53 case tensorflow::error::RESOURCE_EXHAUSTED:
54 TF_SetStatus(tf_status, TF_RESOURCE_EXHAUSTED, message);
55 break;
56 case tensorflow::error::FAILED_PRECONDITION:
57 TF_SetStatus(tf_status, TF_FAILED_PRECONDITION, message);
58 break;
59 case tensorflow::error::ABORTED:
60 TF_SetStatus(tf_status, TF_ABORTED, message);
61 break;
62 case tensorflow::error::OUT_OF_RANGE:
63 TF_SetStatus(tf_status, TF_OUT_OF_RANGE, message);
64 break;
65 case tensorflow::error::UNIMPLEMENTED:
66 TF_SetStatus(tf_status, TF_UNIMPLEMENTED, message);
67 break;
68 case tensorflow::error::INTERNAL:
69 TF_SetStatus(tf_status, TF_INTERNAL, message);
70 break;
71 case tensorflow::error::UNAVAILABLE:
72 TF_SetStatus(tf_status, TF_UNAVAILABLE, message);
73 break;
74 case tensorflow::error::DATA_LOSS:
75 TF_SetStatus(tf_status, TF_DATA_LOSS, message);
76 break;
77 default:
78 assert(0);
79 break;
80 }
81 }
82
StatusFromTF_Status(const TF_Status * tf_status)83 Status StatusFromTF_Status(const TF_Status* tf_status) {
84 return tf_status->status;
85 }
86
87 } // namespace tensorflow
88