Fix lazy coding of ereport in pgpool_adm extension.
authorTatsuo Ishii <ishii@sraoss.co.jp>
Tue, 7 Jul 2020 03:35:10 +0000 (12:35 +0900)
committerTatsuo Ishii <ishii@sraoss.co.jp>
Tue, 7 Jul 2020 03:46:00 +0000 (12:46 +0900)
Before it was coded that ereport's "domain" parameters were just "0".
This generated lots of compiler warning. To fix this give plausible
error codes to each ereport call.

src/sql/pgpool_adm/pgpool_adm.c

index ac85a28cdac1291e71f64eb404538bffe6da6941..de94d49c73b1dfd0790fb99bc3912ae041a9eaba 100644 (file)
@@ -48,7 +48,7 @@ connect_to_server(char* host, int port, char* user, char* pass)
        PCPConnInfo* pcpConnInfo;
        pcpConnInfo = pcp_connect(host, port, user, pass, NULL);
        if (PCPConnectionStatus(pcpConnInfo) != PCP_CONNECTION_OK)
-               ereport(ERROR,(0,
+               ereport(ERROR,(errcode(ERRCODE_CONNECTION_FAILURE),
                                           errmsg("connection to PCP server failed."),
                                           errdetail("%s\n",pcp_get_last_error(pcpConnInfo)?pcp_get_last_error(pcpConnInfo):"unknown reason")));
 
@@ -129,7 +129,7 @@ _pcp_node_info(PG_FUNCTION_ARGS)
        HeapTuple tuple;
 
        if (nodeID < 0 || nodeID >= MAX_NUM_BACKENDS)
-               ereport(ERROR, (0, errmsg("NodeID is out of range.")));
+               ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("NodeID is out of range.")));
 
        if (PG_NARGS() == 5)
        {
@@ -146,7 +146,7 @@ _pcp_node_info(PG_FUNCTION_ARGS)
        }
        else
        {
-               ereport(ERROR, (0, errmsg("Wrong number of argument.")));
+               ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("Wrong number of argument.")));
        }
 
        pcpResInfo = pcp_node_info(pcpConnInfo,nodeID);
@@ -155,7 +155,7 @@ _pcp_node_info(PG_FUNCTION_ARGS)
                char *error = pcp_get_last_error(pcpConnInfo)? pstrdup(pcp_get_last_error(pcpConnInfo)):NULL;
                pcp_disconnect(pcpConnInfo);
                pcp_free_connection(pcpConnInfo);
-               ereport(ERROR,(0,
+               ereport(ERROR,(errcode(ERRCODE_INTERNAL_ERROR),
                                        errmsg("failed to get node information"),
                                           errdetail("%s\n",error?error:"unknown reason")));
        }
@@ -258,7 +258,7 @@ _pcp_pool_status(PG_FUNCTION_ARGS)
                else
                {
                        MemoryContextSwitchTo(oldcontext);
-                       ereport(ERROR, (0, errmsg("Wrong number of argument.")));
+                       ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("Wrong number of argument.")));
                }
 
                pcpResInfo = pcp_pool_status(pcpConnInfo);
@@ -269,7 +269,7 @@ _pcp_pool_status(PG_FUNCTION_ARGS)
                        pcp_free_connection(pcpConnInfo);
 
                        MemoryContextSwitchTo(oldcontext);
-                       ereport(ERROR,(0,
+                       ereport(ERROR,(errcode(ERRCODE_INTERNAL_ERROR),
                                                   errmsg("failed to get pool status"),
                                                   errdetail("%s\n",error?error:"unknown reason")));
                }
@@ -379,7 +379,7 @@ _pcp_node_count(PG_FUNCTION_ARGS)
        }
        else
        {
-               ereport(ERROR, (0, errmsg("Wrong number of argument.")));
+               ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("Wrong number of argument.")));
        }
 
        pcpResInfo = pcp_node_count(pcpConnInfo);
@@ -389,7 +389,7 @@ _pcp_node_count(PG_FUNCTION_ARGS)
                char *error = pcp_get_last_error(pcpConnInfo)? pstrdup(pcp_get_last_error(pcpConnInfo)):NULL;
                pcp_disconnect(pcpConnInfo);
                pcp_free_connection(pcpConnInfo);
-               ereport(ERROR,(0,
+               ereport(ERROR,(errcode(ERRCODE_INTERNAL_ERROR),
                                           errmsg("failed to get node count"),
                                           errdetail("%s\n",error?error:"unknown reason")));
        }
@@ -419,7 +419,7 @@ _pcp_attach_node(PG_FUNCTION_ARGS)
        PCPResultInfo* pcpResInfo;
 
        if (nodeID < 0 || nodeID >= MAX_NUM_BACKENDS)
-               ereport(ERROR, (0, errmsg("NodeID is out of range.")));
+               ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("NodeID is out of range.")));
 
        if (PG_NARGS() == 5)
        {
@@ -436,7 +436,7 @@ _pcp_attach_node(PG_FUNCTION_ARGS)
        }
        else
        {
-               ereport(ERROR, (0, errmsg("Wrong number of argument.")));
+               ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("Wrong number of argument.")));
        }
 
        pcpResInfo = pcp_attach_node(pcpConnInfo,nodeID);
@@ -446,7 +446,7 @@ _pcp_attach_node(PG_FUNCTION_ARGS)
                char *error = pcp_get_last_error(pcpConnInfo)? pstrdup(pcp_get_last_error(pcpConnInfo)):NULL;
                pcp_disconnect(pcpConnInfo);
                pcp_free_connection(pcpConnInfo);
-               ereport(ERROR,(0,
+               ereport(ERROR,(errcode(ERRCODE_INTERNAL_ERROR),
                                           errmsg("failed to attach node"),
                                           errdetail("%s\n",error?error:"unknown reason")));
        }
@@ -477,7 +477,7 @@ _pcp_detach_node(PG_FUNCTION_ARGS)
        PCPResultInfo* pcpResInfo;
 
        if (nodeID < 0 || nodeID >= MAX_NUM_BACKENDS)
-               ereport(ERROR, (0, errmsg("NodeID is out of range.")));
+               ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("NodeID is out of range.")));
 
        if (PG_NARGS() == 6)
        {
@@ -494,7 +494,7 @@ _pcp_detach_node(PG_FUNCTION_ARGS)
        }
        else
        {
-               ereport(ERROR, (0, errmsg("Wrong number of argument.")));
+               ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("Wrong number of argument.")));
        }
 
        if (gracefully)
@@ -511,7 +511,7 @@ _pcp_detach_node(PG_FUNCTION_ARGS)
                char *error = pcp_get_last_error(pcpConnInfo)? pstrdup(pcp_get_last_error(pcpConnInfo)):NULL;
                pcp_disconnect(pcpConnInfo);
                pcp_free_connection(pcpConnInfo);
-               ereport(ERROR,(0,
+               ereport(ERROR,(errcode(ERRCODE_INTERNAL_ERROR),
                                           errmsg("failed to detach node"),
                                           errdetail("%s\n",error?error:"unknown reason")));
        }
@@ -521,3 +521,4 @@ _pcp_detach_node(PG_FUNCTION_ARGS)
 
        PG_RETURN_BOOL(true);
 }
+