Add definition of error codes

This commit is contained in:
Parker Liu
2021-10-25 18:34:35 +08:00
parent 2f531522cb
commit 0767be8347
3 changed files with 115 additions and 4 deletions
+1
View File
@@ -109,6 +109,7 @@ set(NEURON_BASE_SOURCES
src/base/neu_tag_group_config.c
src/base/neu_plugin_common.c
src/base/neu_data_expr.c
src/base/neu_errcodes.c
src/connection/tcp_client.c
src/utils/atomic_data.c
src/utils/mem_alloc.c
+35 -4
View File
@@ -24,12 +24,43 @@
extern "C" {
#endif
#define NEU_ERRORCODE_NONE 0x00000000
#define NEU_ERRORCODE_OUTOFMEMORY 0xA0000000
typedef enum {
NEU_ERR_SUCCESS = 0,
NEU_ERR_FAILURE = -1,
NEU_ERR_EINTR = -1,
NEU_ERR_ENOMEM = -2,
NEU_ERR_EINVAL = -3,
NEU_ERR_EBUSY = -4,
NEU_ERR_ETIMEDOUT = -5,
NEU_ERR_ECONNREFUSED = -6,
NEU_ERR_ECLOSED = -7,
NEU_ERR_EAGAIN = -8,
NEU_ERR_ENOTSUP = -9,
NEU_ERR_EADDRINUSE = -10,
NEU_ERR_ESTATE = -11,
NEU_ERR_ENOENT = -12,
NEU_ERR_EPROTO = -13,
NEU_ERR_EUNREACHABLE = -14,
NEU_ERR_EADDRINVAL = -15,
NEU_ERR_EPERM = -16,
NEU_ERR_EMSGSIZE = -17,
NEU_ERR_ECONNABORTED = -18,
NEU_ERR_ECONNRESET = -19,
NEU_ERR_ECANCELED = -20,
NEU_ERR_ENOFILES = -21,
NEU_ERR_ENOSPC = -22,
NEU_ERR_EEXIST = -23,
NEU_ERR_EREADONLY = -24,
NEU_ERR_EWRITEONLY = -25,
NEU_ERR_ECRYPTO = -26,
NEU_ERR_EPEERAUTH = -27,
NEU_ERR_ENOARG = -28,
NEU_ERR_EAMBIGUOUS = -29,
NEU_ERR_EBADTYPE = -30,
NEU_ERR_ECONNSHUT = -31,
NEU_ERR_EINTERNAL = -1000, // A neuron interanl error
NEU_ERR_FAILURE = -1001 // A general error
} neu_err_code_e;
#ifdef __cplusplus
+79
View File
@@ -0,0 +1,79 @@
/**
* NEURON IIoT System for Industry 4.0
* Copyright (C) 2020-2021 EMQ Technologies Co., Ltd All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
#include "neu_errcodes.h"
#include "stdio.h"
#include "stdlib.h"
static const struct {
int code;
const char *msg;
} neu_errors[] = {
// clang-format off
{ 0, "Successful" },
{ NEU_ERR_EINTR, "Interrupted" },
{ NEU_ERR_ENOMEM, "Out of memory" },
{ NEU_ERR_EINVAL, "Invalid argument" },
{ NEU_ERR_EBUSY, "Resource busy" },
{ NEU_ERR_ETIMEDOUT, "Timed out" },
{ NEU_ERR_ECONNREFUSED, "Connection refused" },
{ NEU_ERR_ECLOSED, "Object closed" },
{ NEU_ERR_EAGAIN, "Try again" },
{ NEU_ERR_ENOTSUP, "Not supported" },
{ NEU_ERR_EADDRINUSE, "Address in use" },
{ NEU_ERR_ESTATE, "Incorrect state" },
{ NEU_ERR_ENOENT, "Entry not found" },
{ NEU_ERR_EPROTO, "Protocol error" },
{ NEU_ERR_EUNREACHABLE, "Destination unreachable" },
{ NEU_ERR_EADDRINVAL, "Address invalid" },
{ NEU_ERR_EPERM, "Permission denied" },
{ NEU_ERR_EMSGSIZE, "Message too large" },
{ NEU_ERR_ECONNRESET, "Connection reset" },
{ NEU_ERR_ECONNABORTED, "Connection aborted" },
{ NEU_ERR_ECANCELED, "Operation canceled" },
{ NEU_ERR_ENOFILES, "Out of files" },
{ NEU_ERR_ENOSPC, "Out of space" },
{ NEU_ERR_EEXIST, "Resource already exists" },
{ NEU_ERR_EREADONLY, "Read only resource" },
{ NEU_ERR_EWRITEONLY, "Write only resource" },
{ NEU_ERR_ECRYPTO, "Cryptographic error" },
{ NEU_ERR_EPEERAUTH, "Peer could not be authenticated" },
{ NEU_ERR_ENOARG, "Option requires argument" },
{ NEU_ERR_EAMBIGUOUS, "Ambiguous option" },
{ NEU_ERR_EBADTYPE, "Incorrect type" },
{ NEU_ERR_ECONNSHUT, "Connection shutdown" },
{ NEU_ERR_EINTERNAL, "Internal error detected" },
{ 0, NULL },
// clang-format on
};
// Misc.
const char *neu_strerror(int num)
{
static char unknownerrbuf[32];
for (int i = 0; neu_errors[i].msg != NULL; i++) {
if (neu_errors[i].code == num) {
return (neu_errors[i].msg);
}
}
(void) snprintf(unknownerrbuf, sizeof(unknownerrbuf), "Unknown error #%d",
num);
return (unknownerrbuf);
}