[Glacier] Add proper string formatting for ErrorCodes.
This commit is contained in:
		
							parent
							
								
									a93aa3a426
								
							
						
					
					
						commit
						9f0e87b51d
					
				|  | @ -1,4 +1,5 @@ | |||
| set(glacier_files | ||||
|   status/error.cpp | ||||
|   string/string.cpp | ||||
|   string/string_builder.cpp | ||||
|   string/string_view.cpp | ||||
|  |  | |||
|  | @ -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); \ | ||||
|  |  | |||
|  | @ -57,7 +57,7 @@ void StrFormatValue(StringBuilder& builder, const uint64_t& value, | |||
| template <> | ||||
| void StrFormatValue(StringBuilder& builder, const ErrorCode& value, | ||||
|                     StringView opts) { | ||||
|   StrFormatValue(builder, static_cast<uint64_t>(value), opts); | ||||
|   StrFormatValue(builder, ErrorCodeToStr(value), opts); | ||||
| } | ||||
| 
 | ||||
| template <> | ||||
|  |  | |||
|  | @ -7,7 +7,7 @@ | |||
| 
 | ||||
| z_err_t ProcessExit(ZProcessExitReq* req) { | ||||
|   auto curr_thread = gScheduler->CurrentThread(); | ||||
|   dbgln("Exit code: {x}", req->code); | ||||
|   dbgln("Exit code: {}", static_cast<glcr::ErrorCode>(req->code)); | ||||
|   curr_thread->process().Exit(); | ||||
|   panic("Returned from thread exit"); | ||||
|   return glcr::UNIMPLEMENTED; | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue