Skip to content

Commit f76ed0a

Browse files
authored
Merge pull request #552 from OpenVicProject/add/error-codes
Add Error enum
2 parents e72a426 + 58e45ba commit f76ed0a

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#pragma once
2+
3+
#include <cstdint>
4+
#include <string_view>
5+
6+
namespace OpenVic {
7+
enum class Error : uint8_t {
8+
OK, // Being 0 means failure can be checked with "if (Error)"
9+
FAILED, // Generic failure
10+
UNAVAILABLE, // Unsupported/unavailable behavior
11+
UNCONFIGURED, // Not properly setup
12+
UNAUTHORIZED,
13+
FILE_NOT_FOUND,
14+
FILE_BAD_PATH,
15+
FILE_NO_PERMISSION,
16+
FILE_ALREADY_IN_USE,
17+
FILE_CANT_OPEN,
18+
FILE_CAN_WRITE,
19+
FILE_CANT_READ,
20+
LOCKED, // Attempted to modify locked object
21+
TIMEOUT,
22+
CANT_CONNECT,
23+
CANT_RESOLVE,
24+
CONNECTION_ERROR,
25+
INVALID_DATA,
26+
INVALID_PARAMETER,
27+
ALREADY_EXISTS,
28+
DOES_NOT_EXIST,
29+
BUSY,
30+
SKIP,
31+
BUG, // A bug in the software, should be reported
32+
MAX
33+
};
34+
35+
static constexpr std::string_view as_string(Error err) {
36+
switch (err) {
37+
using enum Error;
38+
case OK: return "OK";
39+
case FAILED: return "Failed";
40+
case UNAVAILABLE: return "Unavailable";
41+
case UNCONFIGURED: return "Unconfigured";
42+
case UNAUTHORIZED: return "Unauthorized";
43+
case FILE_NOT_FOUND: return "File not found";
44+
case FILE_BAD_PATH: return "File: Bad path";
45+
case FILE_NO_PERMISSION: return "File: Permission Denied";
46+
case FILE_ALREADY_IN_USE: return "File already in use";
47+
case FILE_CANT_OPEN: return "Can't open file";
48+
case FILE_CAN_WRITE: return "Can't write file";
49+
case FILE_CANT_READ: return "Can't read file";
50+
case LOCKED: return "Locked";
51+
case TIMEOUT: return "Timeout";
52+
case CANT_CONNECT: return "Can't connect";
53+
case CANT_RESOLVE: return "Can't resolve";
54+
case CONNECTION_ERROR: return "Connection error";
55+
case INVALID_DATA: return "Invalid data";
56+
case INVALID_PARAMETER: return "Invalid parameter";
57+
case ALREADY_EXISTS: return "Already exists";
58+
case DOES_NOT_EXIST: return "Does not exist";
59+
case BUSY: return "Busy";
60+
case SKIP: return "Skip";
61+
case BUG: return "Bug";
62+
case MAX: return "";
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)