bdr: adding errcodes to a lot of ereports
authorChristian Kruse <cjk@defunct.ch>
Tue, 13 May 2014 08:40:49 +0000 (10:40 +0200)
committerAndres Freund <andres@anarazel.de>
Thu, 3 Jul 2014 15:55:34 +0000 (17:55 +0200)
contrib/bdr/bdr.c
contrib/bdr/bdr_count.c
contrib/bdr/bdr_executor.c
contrib/bdr/bdr_init_replica.c

index 396062d654ba615764a9dde7560258f5439fe497..7de5c5cc0f80e78b5504a860568e4ba079aedff6 100644 (file)
@@ -169,7 +169,8 @@ bdr_send_feedback(PGconn *conn, XLogRecPtr blockpos, int64 now, bool replyReques
    if (PQputCopyData(conn, replybuf, len) <= 0 || PQflush(conn))
    {
        ereport(ERROR,
-               (errmsg("could not send feedback packet: %s",
+               (errcode(ERRCODE_CONNECTION_FAILURE),
+                errmsg("could not send feedback packet: %s",
                        PQerrorMessage(conn))));
        return false;
    }
@@ -242,7 +243,8 @@ bdr_connect(char *conninfo_repl,
    if (PQstatus(streamConn) != CONNECTION_OK)
    {
        ereport(FATAL,
-               (errmsg("could not connect to the primary server: %s",
+               (errcode(ERRCODE_CONNECTION_FAILURE),
+                errmsg("could not connect to the primary server: %s",
                        PQerrorMessage(streamConn))));
    }
 
@@ -280,7 +282,8 @@ bdr_connect(char *conninfo_repl,
    if (strcmp(remote_sysid, local_sysid) == 0)
    {
        ereport(FATAL,
-               (errmsg("system identifiers must differ between the nodes"),
+               (errcode(ERRCODE_INVALID_NAME),
+                errmsg("system identifiers must differ between the nodes"),
                 errdetail("Both system identifiers are %s.", remote_sysid)));
    }
    else
@@ -829,7 +832,8 @@ bdr_create_con_gucs(char  *name,
 
        PQfreemem(errormsg);
        ereport(ERROR,
-               (errmsg("bdr %s: error in dsn: %s", name, str)));
+               (errcode(ERRCODE_CONFIG_FILE_ERROR),
+                errmsg("bdr %s: error in dsn: %s", name, str)));
    }
 
    cur_option = options;
@@ -838,7 +842,9 @@ bdr_create_con_gucs(char  *name,
        if (strcmp(cur_option->keyword, "dbname") == 0)
        {
            if (cur_option->val == NULL)
-               ereport(ERROR, (errmsg("bdr %s: no dbname set", name)));
+               ereport(ERROR,
+                       (errcode(ERRCODE_CONFIG_FILE_ERROR),
+                        errmsg("bdr %s: no dbname set", name)));
 
            strncpy(NameStr(opts->dbname), cur_option->val,
                    NAMEDATALEN);
@@ -885,7 +891,8 @@ bdr_create_con_gucs(char  *name,
        elog(DEBUG2, "bdr %s: has init_replica=t", name);
        if (database_initcons[off] != NULL)
            ereport(ERROR,
-                   (errmsg("Connections %s and %s on database %s both have bdr_init_replica enabled, cannot continue",
+                   (errcode(ERRCODE_CONFIG_FILE_ERROR),
+                    errmsg("Connections %s and %s on database %s both have bdr_init_replica enabled, cannot continue",
                            name, database_initcons[off], used_databases[off])));
        else
            database_initcons[off] = name; /* no need to pstrdup, see _PG_init */
@@ -1375,7 +1382,8 @@ _PG_init(void)
 
    if (!process_shared_preload_libraries_in_progress)
        ereport(ERROR,
-               (errmsg("bdr can only be loaded via shared_preload_libraries")));
+               (errcode(ERRCODE_CONFIG_FILE_ERROR),
+                errmsg("bdr can only be loaded via shared_preload_libraries")));
 
    if (!commit_ts_enabled)
        ereport(ERROR,
index 94a9a4ca14ce044d15fe4a6e4e2b2f7b481ce443..1ad1ce09d36791efcd2850f2dcaea1512bc1430b 100644 (file)
@@ -301,7 +301,8 @@ pg_stat_get_bdr(PG_FUNCTION_ARGS)
 
    if (!superuser())
        ereport(ERROR,
-               (errmsg("Access to pg_stat_get_bdr() denied as non-superuser")));
+               (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+                errmsg("Access to pg_stat_get_bdr() denied as non-superuser")));
 
    if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo))
        ereport(ERROR,
index cce81bac04e2c405968d89c8481e4352d85779df..af15f5ba76b5d34f8e156f3171f2f92bbd735886 100644 (file)
@@ -86,7 +86,8 @@ UserTableUpdateOpenIndexes(EState *estate, TupleTableSlot *slot)
 
        if (recheckIndexes != NIL)
            ereport(ERROR,
-                   (errmsg("bdr doesn't support index rechecks")));
+                   (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+                    errmsg("bdr doesn't support index rechecks")));
    }
 
    /* FIXME: recheck the indexes */
index 582d8b7c2b7b49262fca55431ece8568b0a1b14f..9ac4c6ab9d4b82ebe061a3f3d080d45bc37423a2 100644 (file)
@@ -355,7 +355,8 @@ bdr_ensure_ext_installed(PGconn *pgconn, Name bdr_conn_name)
        if (PQgetisnull(res, 0, 1))
        {
            ereport(ERROR,
-                   (errmsg("Remote database for BDR connection %s does not have the bdr extension active",
+                   (errcode(ERRCODE_CONFIG_FILE_ERROR),
+                    errmsg("Remote database for BDR connection %s does not have the bdr extension active",
                     NameStr(*bdr_conn_name)),
                     errdetail("no entry with name 'bdr' in pg_extensions"),
                     errhint("add 'bdr' to shared_preload_libraries in postgresql.conf "
@@ -366,7 +367,8 @@ bdr_ensure_ext_installed(PGconn *pgconn, Name bdr_conn_name)
    {
        /* bdr ext is not known to Pg at all */
        ereport(ERROR,
-               (errmsg("Remote PostgreSQL install for bdr connection %s does not have bdr extension installed",
+               (errcode(ERRCODE_CONFIG_FILE_ERROR),
+                errmsg("Remote PostgreSQL install for bdr connection %s does not have bdr extension installed",
                 NameStr(*bdr_conn_name)),
                 errdetail("no entry with name 'bdr' in pg_available_extensions; did you install BDR?")));
    }
@@ -1009,7 +1011,8 @@ bdr_catchup_to_lsn(int cfg_index,
    {
        LWLockRelease(BdrWorkerCtl->lock);
        ereport(ERROR,
-               (errmsg("No free bdr worker slots, bdr_max_workers=%d too low",
+               (errcode(ERRCODE_CONFIGURATION_LIMIT_EXCEEDED),
+                errmsg("No free bdr worker slots, bdr_max_workers=%d too low",
                        bdr_max_workers)));
    }
    BdrWorkerCtl->slots[worker_shmem_idx].worker_type = BDR_WORKER_APPLY;