error.h: Add more helper macros.
[paraslash.git] / error.h
diff --git a/error.h b/error.h
index 1be0536ed67cec6ab80423d51e4e1e9b4ef8c319..2d03585a953f811c5d85cc1cea0cb474a18589c3 100644 (file)
--- a/error.h
+++ b/error.h
@@ -6,76 +6,10 @@
 
 /** \file error.h list of error messages for all subsystems */
 
-/** \cond list of all subsystems that support the shiny error facility */
-enum para_subsystem {
-       SS_CLIENT,
-       SS_GUI,
-       SS_TIME,
-       SS_WAV,
-       SS_COMPRESS,
-       SS_CLOSE_ON_FORK,
-       SS_DAEMON,
-       SS_DCCP_SEND,
-       SS_RINGBUFFER,
-       SS_RECV,
-       SS_NET,
-       SS_ORTP_RECV,
-       SS_CLIENT_COMMON,
-       SS_AUDIOC,
-       SS_SCHED,
-       SS_AUDIOD,
-       SS_AUDIOD_COMMAND,
-       SS_EXEC,
-       SS_STDIN,
-       SS_STDOUT,
-       SS_SIGNAL,
-       SS_STRING,
-       SS_STAT,
-       SS_GRAB_CLIENT,
-       SS_HTTP_RECV,
-       SS_RECV_COMMON,
-       SS_FILTER_CHAIN,
-       SS_OGGDEC,
-       SS_FILTER,
-       SS_COMMAND,
-       SS_RANDOM_SELECTOR,
-       SS_PLAYLIST_SELECTOR,
-       SS_CRYPT,
-       SS_HTTP_SEND,
-       SS_ORTP_SEND,
-       SS_AFS_COMMON,
-       SS_OGG_AFH,
-       SS_MP3_AFH,
-       SS_AAC_AFH,
-       SS_MP3DEC,
-       SS_AACDEC,
-       SS_AAC_COMMON,
-       SS_SERVER,
-       SS_VSS,
-       SS_MYSQL_SELECTOR,
-       SS_IPC,
-       SS_DCCP,
-       SS_DCCP_RECV,
-       SS_FD,
-       SS_WRITE,
-       SS_WRITE_COMMON,
-       SS_ALSA_WRITE,
-       SS_FILE_WRITE,
-       SS_OSX_WRITE,
-       SS_USER_LIST,
-       SS_CHUNK_QUEUE,
-       SS_AFS,
-       SS_OSL,
-       SS_AFT,
-       SS_MOOD,
-       SS_SCORE,
-       SS_ATTRIBUTE,
-       SS_BLOB,
-       SS_PLAYLIST,
-       SS_SHA1,
-       SS_RBTREE,
-       NUM_SS
-};
+/** \cond */
+
+/* list of all subsystems that use paraslash's error facility */
+DEFINE_ERRLIST_OBJECT_ENUM;
 
 /* these do not need error handling (yet) */
 #define SERVER_ERRORS
@@ -90,121 +24,105 @@ enum para_subsystem {
 #define RINGBUFFER_ERRORS
 #define SCORE_ERRORS
 #define SHA1_ERRORS
+#define RECV_ERRORS
 
 extern const char **para_errlist[];
-/** \endcond */
+
+#define FSCK_ERRORS \
+       PARA_ERROR(FSCK_SYNTAX, "fsck syntax error"), \
+       PARA_ERROR(RANGE_VIOLATION, "range violation detected, very bad"), \
+       PARA_ERROR(NOT_A_REGULAR_FILE, "not a regular file"), \
+
 
 #define OSL_ERRORS \
-       PARA_ERROR(OSL_OPENDIR, "can not open directory"), \
-       PARA_ERROR(OSL_CHDIR, "fixme"), \
-       PARA_ERROR(BAD_DB_DIR, "fixme"), \
-       PARA_ERROR(NO_COLUMN_DESC, "fixme"), \
-       PARA_ERROR(BAD_BASENAME, "fixme"), \
-       PARA_ERROR(BAD_STORAGE_TYPE, "fixme"), \
-       PARA_ERROR(BAD_STORAGE_FLAGS, "fixme"), \
-       PARA_ERROR(NO_COLUMN_NAME, "fixme"), \
-       PARA_ERROR(NO_COLUMNS, "fixme"), \
-       PARA_ERROR(BAD_COLUMN_NAME, "fixme"), \
-       PARA_ERROR(NO_UNIQUE_RBTREE_COLUMN, "fixme"), \
-       PARA_ERROR(NO_RBTREE_COL, "fixme"), \
-       PARA_ERROR(DUPLICATE_COL_NAME, "fixme"), \
-       PARA_ERROR(BAD_STORAGE_SIZE, "fixme"), \
-       PARA_ERROR(NO_COMPARE_FUNC, "fixme"), \
-       PARA_ERROR(NULL_OBJECT, "fixme"), \
-       PARA_ERROR(BAD_DATA_SIZE, "fixme"), \
-       PARA_ERROR(NOT_MAPPED, "fixme"), \
-       PARA_ERROR(ALREADY_MAPPED, "fixme"), \
-       PARA_ERROR(BAD_SIZE, "fixme"), \
-       PARA_ERROR(TRUNC, "fixme"), \
-       PARA_ERROR(UNLINK, "fixme"), \
-       PARA_ERROR(EXIST, "fixme"), \
-       PARA_ERROR(ISDIR, "fixme"), \
-       PARA_ERROR(NOTDIR, "fixme"), \
-       PARA_ERROR(NOENT, "fixme"), \
-       PARA_ERROR(OSL_PERM, "fixme"), \
+       PARA_ERROR(BAD_DB_DIR, "invalid database directory"), \
+       PARA_ERROR(NO_COLUMN_DESC, "missing column description"), \
+       PARA_ERROR(BAD_NAME, "invalid name for a column/table"), \
+       PARA_ERROR(BAD_STORAGE_TYPE, "invalid storage type"), \
+       PARA_ERROR(BAD_STORAGE_FLAGS, "invalid storage flags"), \
+       PARA_ERROR(NO_COLUMN_NAME, "missing column name"), \
+       PARA_ERROR(NO_COLUMNS, "at least one column required"), \
+       PARA_ERROR(BAD_COLUMN_NAME, "invalid name for a table column"), \
+       PARA_ERROR(NO_UNIQUE_RBTREE_COLUMN, "need at least one mapped column with OSL_UNIQE and OSL_RBTREE OSL"), \
+       PARA_ERROR(NO_RBTREE_COL, "at least one column needs an rbtree"), \
+       PARA_ERROR(DUPLICATE_COL_NAME, "column name given twice"), \
+       PARA_ERROR(BAD_STORAGE_SIZE, "invalid storage size"), \
+       PARA_ERROR(NO_COMPARE_FUNC, "missing compare function"), \
+       PARA_ERROR(BAD_DATA_SIZE, "wrong data size for fixed-size column"), \
+       PARA_ERROR(NOT_MAPPED, "file not mapped"), \
+       PARA_ERROR(ALREADY_MAPPED, "file already mapped"), \
+       PARA_ERROR(BAD_SIZE, "invalid size specified"), \
+       PARA_ERROR(TRUNC, "failed to truncate file"), \
+       PARA_ERROR(UNLINK, "failed to remove file"), \
        PARA_ERROR(BAD_TABLE, "table not open"), \
-       PARA_ERROR(BAD_TABLE_HEADER, "table header corruption"), \
-       PARA_ERROR(BAD_TABLE_DESC, "fixme"), \
+       PARA_ERROR(BAD_TABLE_DESC, "invalid table description"), \
        PARA_ERROR(RB_KEY_EXISTS, "key already exists in rbtree"), \
        PARA_ERROR(RB_KEY_NOT_FOUND, "key not found in rbtree"), \
-       PARA_ERROR(BAD_ID, "fixme"), \
-       PARA_ERROR(INDEX_CORRUPTION, "fixme"), \
-       PARA_ERROR(BAD_OFFSET, "fixme"), \
-       PARA_ERROR(INVALID_OBJECT, "fixme"), \
-       PARA_ERROR(MKDIR, "failed to create directory"), \
-       PARA_ERROR(OPEN, "failed to open file"), \
+       PARA_ERROR(BAD_ROW_NUM, "invalid row number"), \
+       PARA_ERROR(INDEX_CORRUPTION, "index corruption detected"), \
+       PARA_ERROR(INVALID_OBJECT, "reference to invalid object"), \
        PARA_ERROR(STAT, "can not stat file"), \
        PARA_ERROR(FSTAT, "fstat error"), \
-       PARA_ERROR(RENAME, "fixme"), \
+       PARA_ERROR(RENAME, "rename failed"), \
        PARA_ERROR(EMPTY, "file empty"), \
-       PARA_ERROR(NOSPC, "fixme"), \
        PARA_ERROR(MMAP, "mmap error"), \
        PARA_ERROR(MUNMAP, "munmap failed"), \
-       PARA_ERROR(WRITE, "fixme"), \
-       PARA_ERROR(LSEEK, "fixme"), \
-       PARA_ERROR(BUSY, "fixme"), \
-       PARA_ERROR(SHORT_TABLE, "fixme"), \
-       PARA_ERROR(NO_MAGIC, "fixme"), \
-       PARA_ERROR(VERSION_MISMATCH, "fixme"), \
-       PARA_ERROR(BAD_COLUMN_NUM, "fixme"), \
-       PARA_ERROR(BAD_TABLE_FLAGS, "fixme"), \
-       PARA_ERROR(RBTREE_EMPTY, "fixme"), \
-       PARA_ERROR(BAD_ROW, "fixme"), \
-       PARA_ERROR(OSL_GETCWD, "can not get current working directory"), \
-       PARA_ERROR(OSL_LSTAT, "fixme"), \
+       PARA_ERROR(WRITE, "write error"), \
+       PARA_ERROR(LSEEK, "lseek error"), \
+       PARA_ERROR(BUSY, "table is busy"), \
+       PARA_ERROR(SHORT_TABLE, "table too short"), \
+       PARA_ERROR(NO_MAGIC, "missing table header magic"), \
+       PARA_ERROR(VERSION_MISMATCH, "table version not suppoerted"), \
+       PARA_ERROR(BAD_COLUMN_NUM, "invalid column number"), \
+       PARA_ERROR(BAD_TABLE_FLAGS, "invalid flags in table description"), \
+       PARA_ERROR(BAD_ROW, "invalid row"), \
 
 
 #define RBTREE_ERRORS \
 
 
 #define AFS_ERRORS \
-       PARA_ERROR(AFS_SYNTAX, "fixme"), \
-       PARA_ERROR(FORK, "fixme"), \
-       PARA_ERROR(BAD_TABLE_NAME, "fixme"), \
-       PARA_ERROR(INPUT_TOO_LARGE, "fixme"), \
+       PARA_ERROR(BAD_TABLE_NAME, "invalid table"), \
+       PARA_ERROR(INPUT_TOO_LARGE, "input too large for stdin command"), \
+       PARA_ERROR(AFS_SYNTAX, "afs syntax error"), \
+       PARA_ERROR(AFS_SIGNAL, "afs caught deadly signal"), \
 
 
 #define MOOD_ERRORS \
-       PARA_ERROR(MOOD_SYNTAX, "fixme"), \
-       PARA_ERROR(MOOD_REGEX, "fixme"), \
-       PARA_ERROR(NO_MOOD, "fixme"), \
-       PARA_ERROR(MOOD_LOADED, "fixme"), \
-       PARA_ERROR(MOOD_BUSY, "fixme"), \
-       PARA_ERROR(NOT_ADMISSIBLE, "fixme"), \
-       PARA_ERROR(READ, "fixme"), \
-       PARA_ERROR(ATOL, "fixme"), \
+       PARA_ERROR(MOOD_SYNTAX, "mood syntax error"), \
+       PARA_ERROR(NO_MOOD, "no mood available"), \
+       PARA_ERROR(MOOD_LOADED, "mood loaded"), \
+       PARA_ERROR(NOT_ADMISSIBLE, "file is not admussible"), \
 
 
 #define ATTRIBUTE_ERRORS \
-       PARA_ERROR(ATTR_SYNTAX, "fixme"), \
-       PARA_ERROR(ATTR_EXISTS, "fixme"), \
-       PARA_ERROR(ATTR_TABLE_FULL, "fixme"), \
-       PARA_ERROR(NO_ATTRIBUTES, "fixme"), \
+       PARA_ERROR(ATTR_SYNTAX, "attribute syntax error"), \
+       PARA_ERROR(ATTR_EXISTS, "attribute already exists"), \
+       PARA_ERROR(ATTR_TABLE_FULL, "attribute table full"), \
+       PARA_ERROR(NO_ATTRIBUTES, "no attributes defined yet"), \
 
 #define BLOB_ERRORS \
-       PARA_ERROR(BLOB_SYNTAX, "fixme"), \
-       PARA_ERROR(DUMMY_ROW, "fixme"), \
+       PARA_ERROR(BLOB_SYNTAX, "blob syntax error"), \
+       PARA_ERROR(DUMMY_ROW, "attempted to access blob dummy object"), \
 
 
 #define PLAYLIST_ERRORS \
-       PARA_ERROR(PLAYLIST_SYNTAX, "fixme"), \
-       PARA_ERROR(NO_PLAYLIST, "fixme"), \
-       PARA_ERROR(PLAYLIST_LOADED, "fixme"), \
-       PARA_ERROR(PLAYLIST_EMPTY, "fixme"), \
+       PARA_ERROR(NO_PLAYLIST, "no valid playlist found"), \
+       PARA_ERROR(PLAYLIST_LOADED, ""), /* not really an error */ \
+       PARA_ERROR(PLAYLIST_EMPTY, "attempted to load empty playlist"), \
 
 
 #define AFT_ERRORS \
-       PARA_ERROR(BAD_AFS, "fixme"), \
-       PARA_ERROR(LOCALTIME, "fixme"), \
-       PARA_ERROR(STRFTIME, "fixme"), \
-       PARA_ERROR(BAD_PATH, "fixme"), \
-       PARA_ERROR(BAD_SORT, "fixme"), \
-       PARA_ERROR(FNMATCH, "fixme"), \
-       PARA_ERROR(NO_MATCH, "fixme"), \
-       PARA_ERROR(NO_AFHI, "fixme"), \
-       PARA_ERROR(AFT_SYNTAX, "syntax error"), \
-       PARA_ERROR(AFS_STAT, "stat(2) failed"), \
-       PARA_ERROR(HASH_MISMATCH, "fixme"), \
+       PARA_ERROR(BAD_AFSI, "invaid afs info"), \
+       PARA_ERROR(LOCALTIME, "localtime() failed"), \
+       PARA_ERROR(STRFTIME, "strftime() failed"), \
+       PARA_ERROR(BAD_PATH, "invalid path"), \
+       PARA_ERROR(BAD_SORT, "invalid sorting method"), \
+       PARA_ERROR(FNMATCH, "fnmatch error"), \
+       PARA_ERROR(NO_MATCH, "no matches"), \
+       PARA_ERROR(NO_AFHI, "audio format handler info required"), \
+       PARA_ERROR(AFT_SYNTAX, "audio file table syntax error"), \
+       PARA_ERROR(HASH_MISMATCH, "hash mismatch, consider re-add"), \
 
 
 #define USER_LIST_ERRORS \
@@ -224,8 +142,6 @@ extern const char **para_errlist[];
        PARA_ERROR(AUDIOC_SYNTAX, "audioc syntax error"), \
        PARA_ERROR(AUDIOC_READ, "audioc read error"), \
        PARA_ERROR(AUDIOC_WRITE, "audioc write error"), \
-       PARA_ERROR(INIT_SOCK_ADDR, "can not init socket"), \
-       PARA_ERROR(AUDIOC_CONNECT, "audioc connect error"), \
        PARA_ERROR(AUDIOC_OVERRUN, "audioc buffer overrun"), \
 
 
@@ -287,12 +203,8 @@ extern const char **para_errlist[];
        PARA_ERROR(HTTP_RECV_EOF, "http_recv: end of file"), \
        PARA_ERROR(HTTP_RECV_OVERRUN, "http_recv: outout buffer overrun"), \
 
-
-#define RECV_ERRORS \
-       PARA_ERROR(RECV_SYNTAX, "recv syntax error"), \
-
-
 #define RECV_COMMON_ERRORS \
+       PARA_ERROR(RECV_SYNTAX, "recv syntax error"), \
 
 
 #define AUDIOD_ERRORS \
@@ -359,6 +271,10 @@ extern const char **para_errlist[];
 #define STRING_ERRORS \
        PARA_ERROR(MKSTEMP, "mkstemp error: unable to create tmp file"), \
        PARA_ERROR(FCHMOD, "fchmod error: can not set mode"), \
+       PARA_ERROR(ATOI_OVERFLOW, "value too large"), \
+       PARA_ERROR(STRTOLL, "unknown strtoll error"), \
+       PARA_ERROR(ATOI_NO_DIGITS, "no digits found in string"), \
+       PARA_ERROR(ATOI_JUNK_AT_END, "further characters after number"), \
 
 
 #define EXEC_ERRORS \
@@ -398,14 +314,12 @@ extern const char **para_errlist[];
 
 
 #define VSS_ERRORS \
+       PARA_ERROR(BAD_AUDIO_FILE_SUFFIX, "unknown suffix"), \
        PARA_ERROR(AUDIO_FORMAT, "audio format not recognized"), \
        PARA_ERROR(CHUNK, "unable to get chunk"), \
 
 
 #define AFS_COMMON_ERRORS \
-       PARA_ERROR(GETCWD, "can not get current working directory"), \
-       PARA_ERROR(CHDIR, "can not change directory"), \
-       PARA_ERROR(OPENDIR, "can not open directory"), \
        PARA_ERROR(LSTAT, "lstat error"), \
 
 
@@ -494,9 +408,22 @@ extern const char **para_errlist[];
 
 
 #define FD_ERRORS \
+       PARA_ERROR(NOTDIR, "error: not a directory"), \
        PARA_ERROR(F_GETFL, "failed to get fd flags"), \
        PARA_ERROR(F_SETFL, "failed to set fd flags"), \
        PARA_ERROR(FGETS, "fgets error"), \
+       PARA_ERROR(EXIST, "file or directory already exists"), \
+       PARA_ERROR(ISDIR, "error: is a directory"), \
+       PARA_ERROR(NOENT, "no such file or directory"), \
+       PARA_ERROR(OPEN_PERM, "open error (permission denied)"), \
+       PARA_ERROR(MKDIR_PERM, "mkdir error (permission denied)"), \
+       PARA_ERROR(MKDIR, "failed to create directory"), \
+       PARA_ERROR(CHDIR, "failed to change directory"), \
+       PARA_ERROR(FCHDIR, "fchdir failed"), \
+       PARA_ERROR(OPENDIR, "can not open directory"), \
+       PARA_ERROR(NOSPC, "no space left on device"), \
+       PARA_ERROR(OPEN, "failed to open file"), \
+       PARA_ERROR(CHDIR_PERM, "insufficient permissions to chdir"), \
 
 
 #define WRITE_ERRORS \
@@ -548,6 +475,7 @@ extern const char **para_errlist[];
 #define CHUNK_QUEUE_ERRORS \
        PARA_ERROR(QUEUE, "packet queue overrun"), \
 
+/** \endcond */
 
 /**
  * the subsystem shift
@@ -588,12 +516,22 @@ extern const char **para_errlist[];
  */
 #define ERRNUM_TO_INDEX(num) (((1 << SS_SHIFT) - 1) & (num))
 
+#define SYSTEM_ERROR_BIT 30
+
+#define IS_SYSTEM_ERROR(num) (!!((num) & (1 << SYSTEM_ERROR_BIT)))
+
+#define ERRNO_TO_PARA_ERROR(num) ((num) | (1 << SYSTEM_ERROR_BIT))
+
+#define IS_SYSTEM_ERRNO(val, _errno) (ERRNO_TO_PARA_ERROR(_errno) == (val))
+
 /**
  * paraslash's version of strerror(3)
  *
  * expands to the error text of \a num (a string constant).
  */
-#define PARA_STRERROR(num) para_errlist[ERRNUM_TO_SS(num)] [ERRNUM_TO_INDEX(num)]
+#define PARA_STRERROR(num) IS_SYSTEM_ERROR(num)? \
+       strerror((num) & ((1 << SYSTEM_ERROR_BIT) - 1)) : \
+       para_errlist[ERRNUM_TO_SS(num)] [ERRNUM_TO_INDEX(num)]
 
 /**
  * define the error list for one subsystem
@@ -618,78 +556,7 @@ extern const char **para_errlist[];
  * 'E_') and gets later redefined to expand to the error text only
  */
 #define PARA_ERROR(err, msg) E_ ## err
-
-// #define SS_NAME(ss) para_errlist[ss]? para_errlist[ss][0] : ""
-
-/** \cond popcorn time */
-SS_ENUM(GUI);
-SS_ENUM(SCHED);
-SS_ENUM(STDIN);
-SS_ENUM(STDOUT);
-SS_ENUM(WAV);
-SS_ENUM(COMPRESS);
-SS_ENUM(TIME);
-SS_ENUM(CLOSE_ON_FORK);
-SS_ENUM(ORTP_RECV);
-SS_ENUM(NET);
-SS_ENUM(RECV);
-SS_ENUM(AUDIOD);
-SS_ENUM(AUDIOD_COMMAND);
-SS_ENUM(EXEC);
-SS_ENUM(SIGNAL);
-SS_ENUM(STRING);
-SS_ENUM(DAEMON);
-SS_ENUM(STAT);
-SS_ENUM(GRAB_CLIENT);
-SS_ENUM(HTTP_RECV);
-SS_ENUM(RECV_COMMON);
-SS_ENUM(FILTER_CHAIN);
-SS_ENUM(OGGDEC);
-SS_ENUM(MP3DEC);
-SS_ENUM(AACDEC);
-SS_ENUM(FILTER);
-SS_ENUM(MP3_AFH);
-SS_ENUM(OGG_AFH);
-SS_ENUM(AAC_AFH);
-SS_ENUM(AAC_COMMON);
-SS_ENUM(SERVER);
-SS_ENUM(VSS);
-SS_ENUM(COMMAND);
-SS_ENUM(RANDOM_SELECTOR);
-SS_ENUM(PLAYLIST_SELECTOR);
-SS_ENUM(CRYPT);
-SS_ENUM(HTTP_SEND);
-SS_ENUM(ORTP_SEND);
-SS_ENUM(AFS_COMMON);
-SS_ENUM(MYSQL_SELECTOR);
-SS_ENUM(IPC);
-SS_ENUM(DCCP);
-SS_ENUM(DCCP_RECV);
-SS_ENUM(DCCP_SEND);
-SS_ENUM(FD);
-SS_ENUM(WRITE);
-SS_ENUM(WRITE_COMMON);
-SS_ENUM(ALSA_WRITE);
-SS_ENUM(FILE_WRITE);
-SS_ENUM(OSX_WRITE);
-SS_ENUM(RINGBUFFER);
-SS_ENUM(CLIENT);
-SS_ENUM(CLIENT_COMMON);
-SS_ENUM(AUDIOC);
-SS_ENUM(USER_LIST);
-SS_ENUM(CHUNK_QUEUE);
-
-SS_ENUM(AFS);
-SS_ENUM(OSL);
-SS_ENUM(AFT);
-SS_ENUM(MOOD);
-SS_ENUM(SCORE);
-SS_ENUM(ATTRIBUTE);
-SS_ENUM(BLOB);
-SS_ENUM(PLAYLIST);
-SS_ENUM(SHA1);
-SS_ENUM(RBTREE);
-/** \endcond */
+#include "error2.h"
 #undef PARA_ERROR
 /* rest of the world only sees the error text */
 #define PARA_ERROR(err, msg) msg