[Glacier] Add proper string formatting for ErrorCodes.
This commit is contained in:
parent
a93aa3a426
commit
9f0e87b51d
5 changed files with 51 additions and 2 deletions
44
lib/glacier/status/error.cpp
Normal file
44
lib/glacier/status/error.cpp
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#include "glacier/status/error.h"
|
||||
|
||||
namespace glcr {
|
||||
|
||||
StringView ErrorCodeToStr(ErrorCode code) {
|
||||
switch (code) {
|
||||
case OK:
|
||||
return "OK";
|
||||
case INVALID_ARGUMENT:
|
||||
return "INVALID_ARGUMENT";
|
||||
case NOT_FOUND:
|
||||
return "NOT_FOUND";
|
||||
case PERMISSION_DENIED:
|
||||
return "PERMISSION_DENIED";
|
||||
case NULL_PTR:
|
||||
return "NULL_PTR";
|
||||
case EMPTY:
|
||||
return "EMPTY";
|
||||
case ALREADY_EXISTS:
|
||||
return "ALREADY_EXISTS";
|
||||
case BUFFER_SIZE:
|
||||
return "BUFFER_SIZE";
|
||||
case FAILED_PRECONDITION:
|
||||
return "FAILED_PRECONDITION";
|
||||
case INTERNAL:
|
||||
return "INTERNAL";
|
||||
case UNIMPLEMENTED:
|
||||
return "UNIMPLEMENTED";
|
||||
case EXHAUSTED:
|
||||
return "EXHAUSTED";
|
||||
case INVALID_RESPONSE:
|
||||
return "INVALID_RESPONSE";
|
||||
case CAP_NOT_FOUND:
|
||||
return "CAP_NOT_FOUND";
|
||||
case CAP_WRONG_TYPE:
|
||||
return "CAP_WRONG_TYPE";
|
||||
case CAP_PERMISSION_DENIED:
|
||||
return "CAP_PERMISSION_DENIED";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace glcr
|
||||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "glacier/string/string_view.h"
|
||||
|
||||
namespace glcr {
|
||||
|
||||
enum ErrorCode : uint64_t {
|
||||
|
|
@ -29,6 +31,8 @@ enum ErrorCode : uint64_t {
|
|||
|
||||
};
|
||||
|
||||
StringView ErrorCodeToStr(ErrorCode code);
|
||||
|
||||
#define RET_ERR(expr) \
|
||||
{ \
|
||||
glcr::ErrorCode _tmp_err = static_cast<glcr::ErrorCode>(expr); \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue