From 3afe919afe7b71839c26d1d654750f9525befa38 Mon Sep 17 00:00:00 2001 From: Bharath Rupireddy Date: Mon, 15 Feb 2021 08:07:58 +0530 Subject: [PATCH v1] delta patch for reporting error --- src/backend/commands/subscriptioncmds.c | 70 +++++++++++++------------ 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/src/backend/commands/subscriptioncmds.c b/src/backend/commands/subscriptioncmds.c index ad271deb64..f7b1b1f002 100644 --- a/src/backend/commands/subscriptioncmds.c +++ b/src/backend/commands/subscriptioncmds.c @@ -1609,7 +1609,8 @@ merge_subpublications(HeapTuple tuple, List *newpublist, bool addpub) Datum datum; bool isnull; List *publist = NIL; - List *errlist = NIL; + StringInfoData errstr; + int errstrcnt = 0; ListCell *lc; /* Get publications */ @@ -1618,7 +1619,9 @@ merge_subpublications(HeapTuple tuple, List *newpublist, bool addpub) Anum_pg_subscription_subpublications, &isnull); Assert(!isnull); + publist = textarray_to_stringlist(DatumGetArrayTypeP(datum)); + initStringInfo(&errstr); foreach(lc, newpublist) { @@ -1632,9 +1635,17 @@ merge_subpublications(HeapTuple tuple, List *newpublist, bool addpub) if (strcmp(name, pubname) == 0) { if (addpub) - errlist = lappend(errlist, makeString(name)); + { + errstrcnt++; + + if (errstrcnt == 1) + appendStringInfo(&errstr, _("\"%s\""), name); + else + appendStringInfo(&errstr, _(", \"%s\""), name); + } else publist = list_delete_cell(publist, cell); + break; } } @@ -1642,45 +1653,36 @@ merge_subpublications(HeapTuple tuple, List *newpublist, bool addpub) if (addpub && cell == NULL) publist = lappend(publist, makeString(name)); else if (!addpub && cell == NULL) - errlist = lappend(errlist, makeString(name)); - } - - if (errlist != NIL) - { - StringInfoData errstr; - bool first = true; - int len = list_length(errlist); - - initStringInfo(&errstr); - if (len == 1) - appendStringInfo(&errstr, "publication name"); - else - appendStringInfo(&errstr, "publication names"); - - appendStringInfoString(&errstr, " \""); - foreach(lc, errlist) { - char *name = strVal(lfirst(lc)); + errstrcnt++; - if (first) - appendStringInfo(&errstr, "%s", name); + if (errstrcnt == 1) + appendStringInfo(&errstr, _("\"%s\""), name); else - appendStringInfo(&errstr, ", %s", name); - - first = false; + appendStringInfo(&errstr, _(", \"%s\""), name); } - appendStringInfoChar(&errstr, '"'); + } + if (errstrcnt >= 1) + { if (addpub) - appendStringInfo(&errstr, " %s already in subscription", - len == 1 ? "is" : "are"); + { + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg_plural("publication \"%s\" is already present in the subscription", + "publications \"%s\" are already present in the subscription", + errstrcnt, + errstr.data))); + } else - appendStringInfo(&errstr, " %s no exist in subscription", - len == 1 ? "does" : "do"); - - ereport(ERROR, - (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("%s", errstr.data))); + { + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg_plural("publication \"%s\" doesn't exist in the subscription", + "publications \"%s\" do not exist in the subscription", + errstrcnt, + errstr.data))); + } } if (publist == NIL) -- 2.25.1