>From d382a1933f3b5875c8e7f5b688b9104543263d3c Mon Sep 17 00:00:00 2001
From: Daniel Gustafsson <daniel@yesql.se>
Date: Mon, 26 Jun 2017 17:26:47 +0200
Subject: [PATCH 6/6] Improve consistency in "object not found" notices in psql

When a \dXXX metacommand failed to find an object, there were some
variability on the response. This aims to make it more consistent by
applying:

* Use psql_error() for all messages regarding objects not being found.
  It's arguably not an error per se, but at least printing all notices
  to the same output channel makes it consistent.
* Formulate the notices in the same way for all objects
* Guard against pattern being NULL
* Never be completely silent unless in QUIET mode, add not found notice
  on the object which lacked it
---
 src/bin/psql/describe.c | 32 ++++++++++++++++++++++++++------
 1 file changed, 26 insertions(+), 6 deletions(-)

diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index f72670eb23..30ca13d024 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -1322,8 +1322,13 @@ describeTableDetails(const char *pattern, bool verbose, bool showSystem)
 	if (PQntuples(res) == 0)
 	{
 		if (!pset.quiet)
-			psql_error("Did not find any relation named \"%s\".\n",
-					   pattern);
+		{
+			if (pattern)
+				psql_error("Did not find any relation named \"%s\".\n",
+						   pattern);
+			else
+				psql_error("Did not find any relations.\n");
+		}
 		PQclear(res);
 		return false;
 	}
@@ -3265,9 +3270,9 @@ listDbRoleSettings(const char *pattern, const char *pattern2)
 	if (PQntuples(res) == 0 && !pset.quiet)
 	{
 		if (pattern)
-			fprintf(pset.queryFout, _("No matching settings found.\n"));
+			psql_error("Did not find any settings matching \"%s\".\n", pattern);
 		else
-			fprintf(pset.queryFout, _("No settings found.\n"));
+			psql_error("Did not find any settings.\n");
 	}
 	else
 	{
@@ -3430,9 +3435,9 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys
 	if (PQntuples(res) == 0 && !pset.quiet)
 	{
 		if (pattern)
-			fprintf(pset.queryFout, _("No matching relations found.\n"));
+			psql_error("Did not find any relation named \"%s\".\n", pattern);
 		else
-			fprintf(pset.queryFout, _("No relations found.\n"));
+			psql_error("Did not find any relations.\n");
 	}
 	else
 	{
@@ -5163,6 +5168,21 @@ describePublications(const char *pattern)
 		return false;
 	}
 
+	if (PQntuples(res) == 0)
+	{
+		if (!pset.quiet)
+		{
+			if (pattern)
+				psql_error("Did not find publication named \"%s\".\n", pattern);
+			else
+				psql_error("Did not find any publications.\n");
+		}
+
+		termPQExpBuffer(&buf);
+		PQclear(res);
+		return false;
+	}
+
 	for (i = 0; i < PQntuples(res); i++)
 	{
 		const char	align = 'l';
-- 
2.13.0.rc0.45.ge2cb6ab.dirty

