]> granicus.if.org Git - postgresql/commitdiff
Fix more user-visible elog() calls.
authorRobert Haas <rhaas@postgresql.org>
Thu, 5 Oct 2017 11:58:02 +0000 (07:58 -0400)
committerRobert Haas <rhaas@postgresql.org>
Thu, 5 Oct 2017 12:32:48 +0000 (08:32 -0400)
Michael Paquier discovered that this could be triggered via SQL;
give a nicer message instead.

Patch by Michael Paquier, reviewed by Masahiko Sawada.

Discussion: http://postgr.es/m/CAB7nPqQtPg+LKKtzdKN26judHcvPZ0s1gNigzOT4j8CYuuuBYg@mail.gmail.com

contrib/test_decoding/expected/replorigin.out
contrib/test_decoding/sql/replorigin.sql
src/backend/replication/logical/origin.c

index c0f512579ca90bed5becf46e448780a32642dd52..52a52df1598aacc7b4db6b335ed3e1609ba9fdf1 100644 (file)
@@ -26,7 +26,14 @@ SELECT pg_replication_origin_drop('test_decoding: temp');
 (1 row)
 
 SELECT pg_replication_origin_drop('test_decoding: temp');
-ERROR:  cache lookup failed for replication origin 'test_decoding: temp'
+ERROR:  replication origin "test_decoding: temp" does not exist
+-- various failure checks for undefined slots
+select pg_replication_origin_advance('test_decoding: temp', '0/1');
+ERROR:  replication origin "test_decoding: temp" does not exist
+select pg_replication_origin_session_setup('test_decoding: temp');
+ERROR:  replication origin "test_decoding: temp" does not exist
+select pg_replication_origin_progress('test_decoding: temp', true);
+ERROR:  replication origin "test_decoding: temp" does not exist
 SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding');
  ?column? 
 ----------
index e12404e106ed61d48b78ddff2f807b2b3c699967..0e3646a212f47c492cbe0336f70cb8f45fdfcd0e 100644 (file)
@@ -13,6 +13,11 @@ SELECT pg_replication_origin_create('test_decoding: temp');
 SELECT pg_replication_origin_drop('test_decoding: temp');
 SELECT pg_replication_origin_drop('test_decoding: temp');
 
+-- various failure checks for undefined slots
+select pg_replication_origin_advance('test_decoding: temp', '0/1');
+select pg_replication_origin_session_setup('test_decoding: temp');
+select pg_replication_origin_progress('test_decoding: temp', true);
+
 SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding');
 
 -- origin tx
index 06f5317a7508ed278c0f9e9dc8b55167c38f29f0..ad99739971e4e6efb99a54946d9047d77fea5a2b 100644 (file)
@@ -221,8 +221,10 @@ replorigin_by_name(char *roname, bool missing_ok)
                ReleaseSysCache(tuple);
        }
        else if (!missing_ok)
-               elog(ERROR, "cache lookup failed for replication origin '%s'",
-                        roname);
+               ereport(ERROR,
+                               (errcode(ERRCODE_UNDEFINED_OBJECT),
+                                errmsg("replication origin \"%s\" does not exist",
+                                               roname)));
 
        return roident;
 }
@@ -422,8 +424,10 @@ replorigin_by_oid(RepOriginId roident, bool missing_ok, char **roname)
                *roname = NULL;
 
                if (!missing_ok)
-                       elog(ERROR, "cache lookup failed for replication origin with oid %u",
-                                roident);
+                       ereport(ERROR,
+                                       (errcode(ERRCODE_UNDEFINED_OBJECT),
+                                        errmsg("replication origin with OID %u does not exist",
+                                                       roident)));
 
                return false;
        }