virerror: Make it easier to add new error number

In v5.0.0-rc1~94 we switched from one huge switch() to an array
for translating error numbers into error messages. However, the
array is declared to have VIR_ERR_NUMBER_LAST items which makes
it impossible to spot this place by compile checking when adding
new error number.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
Michal Privoznik 2020-01-09 09:53:31 +01:00
parent 0604b9e627
commit 4a09c143f6
2 changed files with 10 additions and 1 deletions

View File

@ -1657,6 +1657,13 @@ class CParser:
token = ("name", "virloginit")
return token
elif token[0] == "name" and token[1] == "G_STATIC_ASSERT":
# skip whole line
while token is not None and not (token[0] == "sep" and
token[1] == ";"):
token = self.token()
return self.token()
elif token[0] == "name":
if self.type == "":
self.type = token[1]

View File

@ -910,7 +910,7 @@ typedef struct {
} virErrorMsgTuple;
const virErrorMsgTuple virErrorMsgStrings[VIR_ERR_NUMBER_LAST] = {
static const virErrorMsgTuple virErrorMsgStrings[] = {
[VIR_ERR_OK] = { NULL, NULL },
[VIR_ERR_INTERNAL_ERROR] = {
N_("internal error"),
@ -1235,6 +1235,8 @@ const virErrorMsgTuple virErrorMsgStrings[VIR_ERR_NUMBER_LAST] = {
N_("network port not found: %s") },
};
G_STATIC_ASSERT(G_N_ELEMENTS(virErrorMsgStrings) == VIR_ERR_NUMBER_LAST);
/**
* virErrorMsg: