Skip to content

Commit

Permalink
Improve error management
Browse files Browse the repository at this point in the history
  • Loading branch information
estebanzimanyi committed Oct 4, 2023
1 parent ed18f85 commit 621a478
Show file tree
Hide file tree
Showing 14 changed files with 571 additions and 425 deletions.
77 changes: 0 additions & 77 deletions meos/include/general/error.h

This file was deleted.

2 changes: 1 addition & 1 deletion meos/include/general/temporal.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
/* PostgreSQL */
#include <postgres.h>
/* MEOS */
#include "general/error.h"
#include <meos.h>
#include "general/meos_catalog.h"
#include "general/span.h"
#include "general/set.h"
Expand Down
41 changes: 41 additions & 0 deletions meos/include/meos.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,47 @@ typedef struct
SkipListElem *elems;
} SkipList;

/*****************************************************************************
* Error codes
*****************************************************************************/

typedef enum
{
MEOS_SUCCESS = 0, // Successful operation

MEOS_ERR_INTERNAL_ERROR = 1, // Unspecified internal error
MEOS_ERR_INTERNAL_TYPE_ERROR = 2, // Internal type error
MEOS_ERR_VALUE_OUT_OF_RANGE = 3, // Internal out of range error
MEOS_ERR_DIVISION_BY_ZERO = 4, // Internal division by zero error
MEOS_ERR_MEMORY_ALLOC_ERROR = 5, // Internal malloc error
MEOS_ERR_AGGREGATION_ERROR = 6, // Internal aggregation error
MEOS_ERR_DIRECTORY_ERROR = 7, // Internal directory error
MEOS_ERR_FILE_ERROR = 8, // Internal file error

MEOS_ERR_INVALID_ARG = 10, // Invalid argument
MEOS_ERR_INVALID_ARG_TYPE = 11, // Invalid argument type
MEOS_ERR_INVALID_ARG_VALUE = 12, // Invalid argument value

MEOS_ERR_MFJSON_INPUT = 20, // MFJSON input error
MEOS_ERR_MFJSON_OUTPUT = 21, // MFJSON output error
MEOS_ERR_TEXT_INPUT = 22, // Text input error
MEOS_ERR_TEXT_OUTPUT = 23, // Text output error
MEOS_ERR_WKB_INPUT = 24, // WKB input error
MEOS_ERR_WKB_OUTPUT = 25, // WKB output error
MEOS_ERR_GEOJSON_INPUT = 26, // GEOJSON input error
MEOS_ERR_GEOJSON_OUTPUT = 27, // GEOJSON output error

} errorCode;

extern void meos_error(int errlevel, int errcode, char *format, ...);

/* Set or read error level */

extern int mobdb_errno(void);
extern int mobdb_errno_set(int err);
extern int mobdb_errno_restore(int err);
extern int mobdb_errno_reset(void);

/*****************************************************************************
* Initialization of the MEOS library
*****************************************************************************/
Expand Down
17 changes: 14 additions & 3 deletions meos/postgres/common/pgfnames.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#include "postgres.h"

#include "../../include/meos.h"

/*
* pgfnames
*
Expand All @@ -35,7 +37,8 @@ pgfnames(const char *path)
dir = opendir(path);
if (dir == NULL)
{
elog(WARNING, "could not open directory \"%s\": %m", path);
meos_error(WARNING, MEOS_ERR_DIRECTORY_ERROR,
"could not open directory \"%s\": %m", path);
return NULL;
}

Expand All @@ -55,12 +58,20 @@ pgfnames(const char *path)
}

if (errno)
elog(WARNING, "could not read directory \"%s\": %m", path);
{
meos_error(WARNING, MEOS_ERR_DIRECTORY_ERROR,
"could not read directory \"%s\": %m", path);
return NULL;
}

filenames[numnames] = NULL;

if (closedir(dir))
elog(WARNING, "could not close directory \"%s\": %m", path);
{
meos_error(WARNING, MEOS_ERR_DIRECTORY_ERROR,
"could not close directory \"%s\": %m", path);
return NULL;
}

return filenames;
}
Expand Down
3 changes: 2 additions & 1 deletion meos/postgres/lib/simplehash.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ SH_SCOPE void SH_STAT(SH_TYPE * tb);
#define sh_error(...) pg_fatal(__VA_ARGS__)
#define sh_log(...) pg_log_info(__VA_ARGS__)
#else
#define sh_error(...) elog(ERROR, __VA_ARGS__)
// #define sh_error(...) elog(ERROR, __VA_ARGS__)
#define sh_error(...) meos_error(ERROR, MEOS_ERR_INTERNAL_ERROR, __VA_ARGS__)
// /* MEOS */
// #define sh_log(...) elog(LOG, __VA_ARGS__)
#endif
Expand Down
7 changes: 0 additions & 7 deletions meos/postgres/postgres.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,6 @@
#define ERROR 21 /* user error - abort transaction; return to known state */
#endif
#define EXIT_FAILURE 1
#define elog(error, ...) \
do { \
fprintf (stderr, __VA_ARGS__); \
fprintf (stderr, "\n"); \
if (error == ERROR) \
exit(EXIT_FAILURE); \
} while(0);

/* MEOS: redefining palloc0, palloc, and pfree */
#if MEOS
Expand Down
15 changes: 11 additions & 4 deletions meos/postgres/timezone/pgtz.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include "utils/timestamp_def.h"
#include "pgtz.h"

#include "../../include/meos.h"

/**
* Structure to represent the timezone cache hash table, which extends
* the `ENTRY` structure used by hsearch
Expand Down Expand Up @@ -199,7 +201,8 @@ ReadDir(DIR *dir, const char *dirname)
/* Give a generic message for AllocateDir failure, if caller didn't */
if (dir == NULL)
{
elog(ERROR, "could not open directory \"%s\": %m", dirname);
meos_error(ERROR, MEOS_ERR_DIRECTORY_ERROR,
"could not open directory \"%s\": %m", dirname);
return NULL;
}

Expand All @@ -208,7 +211,8 @@ ReadDir(DIR *dir, const char *dirname)
return dent;

if (errno)
elog(ERROR, "could not read directory \"%s\": %m", dirname);
meos_error(ERROR, MEOS_ERR_DIRECTORY_ERROR,
"could not read directory \"%s\": %m", dirname);
return NULL;
}

Expand Down Expand Up @@ -335,7 +339,9 @@ pg_tzset(const char *name)
if (!tzparse(uppername, &tzstate, true))
{
/* This really, really should not happen ... */
elog(ERROR, "could not initialize GMT time zone");
meos_error(ERROR, MEOS_ERR_INTERNAL_ERROR,
"could not initialize GMT time zone");
return NULL;
}
/* Use uppercase name as canonical */
strcpy(canonname, uppername);
Expand Down Expand Up @@ -428,7 +434,8 @@ meos_initialize_timezone(const char *tz_str)

session_timezone = pg_tzset(tz_str);
if (! session_timezone)
elog(ERROR, "Failed to initialize local timezone");
meos_error(ERROR, MEOS_ERR_INTERNAL_ERROR,
"Failed to initialize local timezone");
return;
}

Expand Down
Loading

0 comments on commit 621a478

Please sign in to comment.