Error handling: obidebug() with message for all errors, and removed

commands closing directories when an error occurred (creating more
errors).
This commit is contained in:
celinemercier
2015-08-03 15:10:39 +02:00
parent 1e01c9059c
commit 41f627091f
4 changed files with 108 additions and 94 deletions

View File

@ -17,6 +17,7 @@
#include "obidebug.h"
#include "obidmscolumn.h"
#define DEBUG_LEVEL 0
@ -65,6 +66,7 @@ static char *build_directory_name(const char *dms_name)
if (asprintf(&directory_name, "%s.obidms", dms_name) < 0)
{
obi_set_errno(OBIDMS_MEMORY_ERROR);
obidebug(1, "\nProblem building an OBIDMS directory name");
return NULL;
}
@ -72,6 +74,7 @@ static char *build_directory_name(const char *dms_name)
if (strlen(directory_name) >= OBIDMS_MAX_NAME)
{
obi_set_errno(OBIDMS_LONG_NAME_ERROR);
obidebug(1, "\nProblem building an OBIDMS directory name");
free(directory_name);
return NULL;
}
@ -124,7 +127,7 @@ OBIDMS_p obi_create_dms(const char* dms_name)
obi_set_errno(OBIDMS_EXIST_ERROR);
else
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
obidebug(1, "\nProblem creating an OBIDMS directory");
free(directory_name);
return NULL;
}
@ -152,7 +155,6 @@ OBIDMS_p obi_open_dms(const char* dms_name)
directory = opendir(directory_name);
if (directory == NULL)
{
obidebug(1, "Can't open DMS");
switch (errno)
{
case ENOENT:
@ -170,6 +172,7 @@ OBIDMS_p obi_open_dms(const char* dms_name)
default:
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
}
obidebug(1, "\nCan't open OBIDMS directory");
free(directory_name);
return NULL;
}
@ -179,6 +182,7 @@ OBIDMS_p obi_open_dms(const char* dms_name)
if (dms == NULL)
{
obi_set_errno(OBIDMS_MEMORY_ERROR);
obidebug(1, "\nError allocating the memory for the OBIDMS structure");
free(directory_name);
return NULL;
}
@ -207,6 +211,7 @@ OBIDMS_p obi_dms(const char* dms_name)
return obi_open_dms(dms_name);
};
obidebug(1, "\nError checking if an OBIDMS directory exists");
return NULL;
}
@ -223,6 +228,11 @@ int obi_list_columns(OBIDMS_p dms)
d = dms->directory;
dir = readdir(d);
if (dir == NULL)
{
obidebug(1, "\nError reading in the OBIDMS directory");
return -1;
}
fprintf(stderr, "Column name\tData type\tLatest version");
@ -250,7 +260,7 @@ int obi_list_columns(OBIDMS_p dms)
rewinddir(d);
return(0);
return 0;
}
@ -261,6 +271,7 @@ int obi_close_dms(OBIDMS_p dms)
if (closedir(dms->directory) < 0)
{
obi_set_errno(OBIDMS_MEMORY_ERROR);
obidebug(1, "\nError closing an OBIDSM directory");
free(dms);
return -1;
}