blob: 1bc361fd21c0910681da9639438431c1b6469e16 [file] [log] [blame]
#include "error_format.h"
using grpc::Status;
using grpc::StatusCode;
Status bcm_to_grpc_err(bcmos_errno bcm_err, std::string message) {
StatusCode grpc_err = StatusCode::INTERNAL;
switch (bcm_err) {
case BCM_ERR_PARM:
grpc_err = StatusCode::INVALID_ARGUMENT;
break;
case BCM_ERR_RANGE:
grpc_err = StatusCode::OUT_OF_RANGE;
break;
case BCM_ERR_NOT_SUPPORTED:
grpc_err = StatusCode::UNIMPLEMENTED;
break;
case BCM_ERR_NOENT:
case BCM_ERR_NODEV:
grpc_err = StatusCode::NOT_FOUND;
break;
case BCM_ERR_TIMEOUT:
case BCM_ERR_TOO_LONG:
case BCM_ERR_TOO_MANY_REQS:
grpc_err = StatusCode::DEADLINE_EXCEEDED;
break;
case BCM_ERR_ALREADY:
grpc_err = StatusCode::ALREADY_EXISTS;
break;
case BCM_ERR_NO_MORE:
case BCM_ERR_INSUFFICIENT_LIST_MEM:
grpc_err = StatusCode::RESOURCE_EXHAUSTED;
break;
}
message.append(" BCM Error ");
message.append(std::to_string(bcm_err));
return Status(grpc_err, message);
}
std::string grpc_status_code_to_string(StatusCode status_code) {
switch (status_code) {
case StatusCode::OK:
return "StatusCode::OK";
case StatusCode::CANCELLED:
return "StatusCode::CANCELED";
case StatusCode::UNKNOWN:
return "StatusCode::UNKNOWN";
case StatusCode::INVALID_ARGUMENT:
return "StatusCode::INVALID_ARGUMENT";
case StatusCode::DEADLINE_EXCEEDED:
return "StatusCode::DEADLINE_EXCEEDED";
case StatusCode::NOT_FOUND:
return "StatusCode::NOT_FOUND";
case StatusCode::ALREADY_EXISTS:
return "StatusCode::ALREADY_EXISTS";
case StatusCode::PERMISSION_DENIED:
return "StatusCode::PERMISSION_DENIED";
case StatusCode::UNAUTHENTICATED:
return "StatusCode::UNAUTHENTICATED";
case StatusCode::RESOURCE_EXHAUSTED:
return "StatusCode::RESOURCE_EXHAUSTED";
case StatusCode::FAILED_PRECONDITION:
return "StatusCode::FAILED_PRECONDITION";
case StatusCode::ABORTED:
return "StatusCode::ABORTED";
case StatusCode::OUT_OF_RANGE:
return "StatusCode::OUT_OF_RANGE";
case StatusCode::INTERNAL:
return "StatusCode::INTERNAL";
case StatusCode::UNAVAILABLE:
return "StatusCode::UNAVAILABLE";
case StatusCode::DATA_LOSS:
return "StatusCode::DATA_LOSS";
case StatusCode::DO_NOT_USE:
return "StatusCode::DO_NOT_USE";
}
return "Unknown GRPC status Code";
}