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