Polishing of error messages
authorDaniel Kouřil <kouril@ics.muni.cz>
Thu, 9 Jun 2011 10:30:59 +0000 (10:30 +0000)
committerDaniel Kouřil <kouril@ics.muni.cz>
Thu, 9 Jun 2011 10:30:59 +0000 (10:30 +0000)
org.glite.px.proxyrenewal/src/api.c
org.glite.px.proxyrenewal/src/common.c
org.glite.px.proxyrenewal/src/renewd.c

index ac092c8..9e254ed 100644 (file)
@@ -495,8 +495,8 @@ edg_wlpr_GetStatus(const char *filename, char **info)
 static const char* const errTexts[] = {
    "Unexpected EOF from peer",
    "Generic error",
-   "Protocol parse error",
-   "Compulsory element not found in message",
+   "Cannot parse protocol messages",
+   "Obligatory element not found in message",
    "Unknown protocol command",
    "SSL error",
    "Error from Myproxy server",
@@ -510,12 +510,13 @@ static const char* const errTexts[] = {
 const char *
 edg_wlpr_GetErrorText(int code)
 {
-   return code ?
-           (code <= EDG_WLPR_ERROR_BASE ?
-                   strerror(code) :
-                   errTexts[code - EDG_WLPR_ERROR_BASE - 1]
-          ) :
-          NULL;
+    if (code == 0)
+       return "No error";
+    if (code <= EDG_WLPR_ERROR_BASE)
+       return strerror(code);
+    if (code == EDG_WLPR_ERROR_ERRNO)
+       return strerror(errno);
+    return errTexts[code - EDG_WLPR_ERROR_BASE - 1];
 }
 
 int
index 4121a10..1b1463c 100644 (file)
 
 #ident "$Header$"
 
-static const char * const ErrorMsgs[] = {
-    "Connection closed unexpectedly",
-    "Generic error",
-    "Cannot parse protocol messages",
-    "Obligatory item not found in message",
-    "Unkown command",
-    "SSL error",
-    "MyProxy error",
-    "Proxy not registered",
-    "Proxy expired",
-    "VOMS error",
-    "Operation timed out",
-    "System error",
-};
-
 /* nread() and nwrite() never return partial data */
 static int
 nread(int sock, struct timeval *to, char *buf, size_t buf_len, size_t *read_len)
@@ -318,16 +303,6 @@ edg_wlpr_CleanResponse(edg_wlpr_Response *response)
    memset(response, 0, sizeof(*response));
 }
 
-const char *
-edg_wlpr_GetErrorString(int code)
-{
-    if (code == 0)
-       return "No error";
-    if (code <= EDG_WLPR_ERROR_BASE)
-       return strerror(code);
-    return ErrorMsgs[code - EDG_WLPR_ERROR_BASE - 1];
-}
-
 char *
 edg_wlpr_EncodeInt(int num) /* long? time */
 {
index d52ee1d..7fc6e03 100644 (file)
@@ -144,7 +144,7 @@ proto(glite_renewal_core_context ctx, int sock)
    ret = edg_wlpr_Read(sock, &timeout, &buf, &buf_len);
    if (ret) {
       edg_wlpr_Log(ctx, LOG_ERR, "Error reading from client: %s",
-                   edg_wlpr_GetErrorString(ret));
+                   edg_wlpr_GetErrorText(ret));
       return ret;
    }
 
@@ -172,7 +172,7 @@ proto(glite_renewal_core_context ctx, int sock)
    free(buf);
    if (ret) {
       edg_wlpr_Log(ctx, LOG_ERR, "Error sending response to client: %s",
-                   edg_wlpr_GetErrorString(ret));
+                   edg_wlpr_GetErrorText(ret));
       goto end;
    }
 
@@ -252,7 +252,7 @@ decode_request(glite_renewal_core_context ctx, const char *msg, const size_t msg
                           0, &request->version);
    if (ret) {
       edg_wlpr_Log(ctx, LOG_ERR, "Protocol error reading protocol specification: %s",
-                   edg_wlpr_GetErrorString(ret));
+                   edg_wlpr_GetErrorText(ret));
       return ret;
    }
    
@@ -260,7 +260,7 @@ decode_request(glite_renewal_core_context ctx, const char *msg, const size_t msg
                           0, &value);
    if (ret) {
       edg_wlpr_Log(ctx, LOG_ERR, "Protocol error reading command specification: %s",
-                   edg_wlpr_GetErrorString(ret));
+                   edg_wlpr_GetErrorText(ret));
       goto err;
    }
 
@@ -283,7 +283,7 @@ decode_request(glite_renewal_core_context ctx, const char *msg, const size_t msg
                           SEPARATORS, 0, &request->myproxy_server);
    if (ret && ret != EDG_WLPR_ERROR_PROTO_PARSE_NOT_FOUND) {
       edg_wlpr_Log(ctx, LOG_ERR, "Protocol error reading myproxy server specification: %s",
-                   edg_wlpr_GetErrorString(ret));
+                   edg_wlpr_GetErrorText(ret));
       goto err;
    }
 
@@ -300,7 +300,7 @@ decode_request(glite_renewal_core_context ctx, const char *msg, const size_t msg
                           0, &request->proxy_filename);
    if (ret && ret != EDG_WLPR_ERROR_PROTO_PARSE_NOT_FOUND) {
       edg_wlpr_Log(ctx, LOG_ERR, "Protocol error reading proxy specification: %s",
-                   edg_wlpr_GetErrorString(ret));
+                   edg_wlpr_GetErrorText(ret));
       goto err;
    }
 
@@ -318,7 +318,7 @@ decode_request(glite_renewal_core_context ctx, const char *msg, const size_t msg
                           0, &request->jobid);
    if (ret && ret != EDG_WLPR_ERROR_PROTO_PARSE_NOT_FOUND) {
       edg_wlpr_Log(ctx, LOG_ERR, "Protocol error reading JobId : %s",
-                  edg_wlpr_GetErrorString(ret));
+                  edg_wlpr_GetErrorText(ret));
       goto err;
    }