blob: 84605276924cc77440c7cfe2b145001d479d6555 [file] [log] [blame]
Zack Williams477ba092018-10-17 10:50:06 -07001/*
Girish Gowdraa707e7c2019-11-07 11:36:13 +05302 * Copyright 2018-present Open Networking Foundation
Zack Williams477ba092018-10-17 10:50:06 -07003
Girish Gowdraa707e7c2019-11-07 11:36:13 +05304 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
Zack Williams477ba092018-10-17 10:50:06 -07007
Girish Gowdraa707e7c2019-11-07 11:36:13 +05308 * http://www.apache.org/licenses/LICENSE-2.0
Zack Williams477ba092018-10-17 10:50:06 -07009
Girish Gowdraa707e7c2019-11-07 11:36:13 +053010 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Zack Williams477ba092018-10-17 10:50:06 -070016
Nicolas Palpacuer73222e02018-07-16 12:20:26 -040017#include "error_format.h"
18using grpc::Status;
19using grpc::StatusCode;
20
21
22Status bcm_to_grpc_err(bcmos_errno bcm_err, std::string message) {
23 StatusCode grpc_err = StatusCode::INTERNAL;
24
25 switch (bcm_err) {
26 case BCM_ERR_PARM:
27 grpc_err = StatusCode::INVALID_ARGUMENT;
28 break;
29 case BCM_ERR_RANGE:
30 grpc_err = StatusCode::OUT_OF_RANGE;
31 break;
32 case BCM_ERR_NOT_SUPPORTED:
33 grpc_err = StatusCode::UNIMPLEMENTED;
34 break;
35 case BCM_ERR_NOENT:
36 case BCM_ERR_NODEV:
37 grpc_err = StatusCode::NOT_FOUND;
38 break;
39 case BCM_ERR_TIMEOUT:
40 case BCM_ERR_TOO_LONG:
41 case BCM_ERR_TOO_MANY_REQS:
42 grpc_err = StatusCode::DEADLINE_EXCEEDED;
43 break;
44 case BCM_ERR_ALREADY:
45 grpc_err = StatusCode::ALREADY_EXISTS;
46 break;
47 case BCM_ERR_NO_MORE:
48 case BCM_ERR_INSUFFICIENT_LIST_MEM:
49 grpc_err = StatusCode::RESOURCE_EXHAUSTED;
50 break;
51 }
52
Girish Gowdrafb5fa432022-03-25 10:58:55 -070053 message.append(" BCM Error: ");
54 message.append(bcmos_strerror(bcm_err));
Nicolas Palpacuer73222e02018-07-16 12:20:26 -040055
56 return Status(grpc_err, message);
57}
Nicolas Palpacuer967438f2018-09-07 14:41:54 -040058
59std::string grpc_status_code_to_string(StatusCode status_code) {
60 switch (status_code) {
61 case StatusCode::OK:
62 return "StatusCode::OK";
63 case StatusCode::CANCELLED:
64 return "StatusCode::CANCELED";
65 case StatusCode::UNKNOWN:
66 return "StatusCode::UNKNOWN";
67 case StatusCode::INVALID_ARGUMENT:
68 return "StatusCode::INVALID_ARGUMENT";
69 case StatusCode::DEADLINE_EXCEEDED:
70 return "StatusCode::DEADLINE_EXCEEDED";
71 case StatusCode::NOT_FOUND:
72 return "StatusCode::NOT_FOUND";
73 case StatusCode::ALREADY_EXISTS:
74 return "StatusCode::ALREADY_EXISTS";
75 case StatusCode::PERMISSION_DENIED:
76 return "StatusCode::PERMISSION_DENIED";
77 case StatusCode::UNAUTHENTICATED:
78 return "StatusCode::UNAUTHENTICATED";
79 case StatusCode::RESOURCE_EXHAUSTED:
80 return "StatusCode::RESOURCE_EXHAUSTED";
81 case StatusCode::FAILED_PRECONDITION:
82 return "StatusCode::FAILED_PRECONDITION";
83 case StatusCode::ABORTED:
84 return "StatusCode::ABORTED";
85 case StatusCode::OUT_OF_RANGE:
86 return "StatusCode::OUT_OF_RANGE";
87 case StatusCode::INTERNAL:
88 return "StatusCode::INTERNAL";
89 case StatusCode::UNAVAILABLE:
90 return "StatusCode::UNAVAILABLE";
91 case StatusCode::DATA_LOSS:
92 return "StatusCode::DATA_LOSS";
93 case StatusCode::DO_NOT_USE:
94 return "StatusCode::DO_NOT_USE";
95 }
96 return "Unknown GRPC status Code";
97
98}