Inaccurate error message when set fdw batch_size to 0

Started by houzj.fnst@fujitsu.comover 4 years ago25 messages
#1houzj.fnst@fujitsu.com
houzj.fnst@fujitsu.com
1 attachment(s)

Hi,

When testing the fdw batch insert, I found a possible issue.

If I set the batch_size to 0 , it will throw an error:

---------------------
CREATE FOREIGN TABLE test(a int, b varchar)
SERVER testserver
OPTIONS (table_name 'testlocal', batch_size '0');
ERROR: fetch_size requires a non-negative integer value
---------------------

The error message here seems not accurate, because
I can see from the code batch_size should be positive ( > 0).

So, is it better to change the error message to “fetch_size requires a positive integer value” ?
I also found fetch_size has the similar issue, attaching a patch to fix this.

Best regards,
houzj

Attachments:

0001-fix-errmsg-when-set-batchsize-to-0.patchapplication/octet-stream; name=0001-fix-errmsg-when-set-batchsize-to-0.patchDownload
From 5d21bda9a499de3503a0ed88d7b31d2a7e287b7b Mon Sep 17 00:00:00 2001
From: "houzj.fnst" <houzj.fnst@fujitsu.com>
Date: Sat, 8 May 2021 11:16:20 +0800
Subject: [PATCH] fix errmsg when set batchsize to 0

---
 contrib/postgres_fdw/option.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/contrib/postgres_fdw/option.c b/contrib/postgres_fdw/option.c
index 672b55a808..04a8ee1e83 100644
--- a/contrib/postgres_fdw/option.c
+++ b/contrib/postgres_fdw/option.c
@@ -142,7 +142,7 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
 			if (fetch_size <= 0)
 				ereport(ERROR,
 						(errcode(ERRCODE_SYNTAX_ERROR),
-						 errmsg("%s requires a non-negative integer value",
+						 errmsg("%s requires a positive integer value",
 								def->defname)));
 		}
 		else if (strcmp(def->defname, "batch_size") == 0)
@@ -153,7 +153,7 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
 			if (batch_size <= 0)
 				ereport(ERROR,
 						(errcode(ERRCODE_SYNTAX_ERROR),
-						 errmsg("%s requires a non-negative integer value",
+						 errmsg("%s requires a positive integer value",
 								def->defname)));
 		}
 		else if (strcmp(def->defname, "password_required") == 0)
-- 
2.18.4

#2Dilip Kumar
dilipbalaut@gmail.com
In reply to: houzj.fnst@fujitsu.com (#1)
Re: Inaccurate error message when set fdw batch_size to 0

On Sat, May 8, 2021 at 9:09 AM houzj.fnst@fujitsu.com
<houzj.fnst@fujitsu.com> wrote:

The error message here seems not accurate, because

I can see from the code batch_size should be positive ( > 0).

So, is it better to change the error message to “fetch_size requires a positive integer value” ?

I also found fetch_size has the similar issue, attaching a patch to fix this.

Yes, it should be a positive integer, so your change makes sense.

--
Regards,
Dilip Kumar
EnterpriseDB: http://www.enterprisedb.com

#3tsunakawa.takay@fujitsu.com
tsunakawa.takay@fujitsu.com
In reply to: houzj.fnst@fujitsu.com (#1)
RE: Inaccurate error message when set fdw batch_size to 0

From: houzj.fnst@fujitsu.com <houzj.fnst@fujitsu.com>

So, is it better to change the error message to “fetch_size requires a positive integer value” ?
I also found fetch_size has the similar issue, attaching a patch to fix this.

I have a faint memory that I fixed them after receiving the same feedback from someone else, strange... Anyway, thanks.

Regards
Takayuki Tsunakawa

#4Fujii Masao
masao.fujii@oss.nttdata.com
In reply to: tsunakawa.takay@fujitsu.com (#3)
Re: Inaccurate error message when set fdw batch_size to 0

On 2021/05/10 10:26, tsunakawa.takay@fujitsu.com wrote:

From: houzj.fnst@fujitsu.com <houzj.fnst@fujitsu.com>

So, is it better to change the error message to “fetch_size requires a positive integer value” ?
I also found fetch_size has the similar issue, attaching a patch to fix this.

I have a faint memory that I fixed them after receiving the same feedback from someone else, strange... Anyway, thanks.

+1 for the change of the error messages.

One question is; should we back-patch the change of the error message about
fetch_size to back branches? Since this is minor thing, is it enough to apply
the change only to the master? Even if we should do the back-patch,
we would need to wait until upcoming minor release is done before doing that.

Regards,

--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION

#5Tom Lane
tgl@sss.pgh.pa.us
In reply to: Fujii Masao (#4)
Re: Inaccurate error message when set fdw batch_size to 0

Fujii Masao <masao.fujii@oss.nttdata.com> writes:

+1 for the change of the error messages.

Yeah, this error message seems outright buggy. However, it's a minor
matter. Also, some people think "positive" is the same thing as
"non-negative", so maybe we need less ambiguous wording?

One question is; should we back-patch the change of the error message about
fetch_size to back branches? Since this is minor thing, is it enough to apply
the change only to the master? Even if we should do the back-patch,
we would need to wait until upcoming minor release is done before doing that.

+1 for back-patch, but not till after the releases are out. Right now
is no time for inessential changes ...

regards, tom lane

#6Bharath Rupireddy
bharath.rupireddyforpostgres@gmail.com
In reply to: Tom Lane (#5)
Re: Inaccurate error message when set fdw batch_size to 0

On Mon, May 10, 2021 at 12:00 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:

Fujii Masao <masao.fujii@oss.nttdata.com> writes:

+1 for the change of the error messages.

Yeah, this error message seems outright buggy. However, it's a minor
matter. Also, some people think "positive" is the same thing as
"non-negative", so maybe we need less ambiguous wording?

Since value 0 can't be considered as either a positive or negative
integer, I think we can do as following(roughly):

if (value < 0) "requires a zero or positive integer value"
if (value <= 0) "requires a positive integer value"

I'm not sure whether we should consider changing these messages:
remainder for hash partition must be a non-negative integer
parallel vacuum degree must be a non-negative integer
repeat count size must be a non-negative integer
number of workers must be a non-negative integer
%s requires a non-negative numeric value
distance in phrase operator should be non-negative and less than %d

With Regards,
Bharath Rupireddy.
EnterpriseDB: http://www.enterprisedb.com

#7Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bharath Rupireddy (#6)
Re: Inaccurate error message when set fdw batch_size to 0

Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> writes:

On Mon, May 10, 2021 at 12:00 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:

Yeah, this error message seems outright buggy. However, it's a minor
matter. Also, some people think "positive" is the same thing as
"non-negative", so maybe we need less ambiguous wording?

Since value 0 can't be considered as either a positive or negative
integer, I think we can do as following(roughly):

if (value < 0) "requires a zero or positive integer value"
if (value <= 0) "requires a positive integer value"

I was thinking of avoiding the passive voice and writing

"foo must be greater than zero"

which removes all doubt. It's not necessary to keep the "integer"
aspect of the existing text, because if someone had supplied a
non-integer value, that would not have gotten this far anyway.

I'm not sure whether we should consider changing these messages:
remainder for hash partition must be a non-negative integer
parallel vacuum degree must be a non-negative integer
repeat count size must be a non-negative integer
number of workers must be a non-negative integer
%s requires a non-negative numeric value
distance in phrase operator should be non-negative and less than %d

I think for consistency it'd be good to change 'em all. I'm almost
tempted to put this matter into our message style guide too.

regards, tom lane

#8Michael Paquier
michael@paquier.xyz
In reply to: Tom Lane (#7)
Re: Inaccurate error message when set fdw batch_size to 0

On Mon, May 10, 2021 at 10:09:40AM -0400, Tom Lane wrote:

Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> writes:

if (value < 0) "requires a zero or positive integer value"
if (value <= 0) "requires a positive integer value"

I was thinking of avoiding the passive voice and writing

"foo must be greater than zero"

Sounds like a good idea to me.

I'm not sure whether we should consider changing these messages:
remainder for hash partition must be a non-negative integer
parallel vacuum degree must be a non-negative integer
repeat count size must be a non-negative integer
number of workers must be a non-negative integer
%s requires a non-negative numeric value
distance in phrase operator should be non-negative and less than %d

I think for consistency it'd be good to change 'em all. I'm almost
tempted to put this matter into our message style guide too.

+1.
--
Michael
#9Bharath Rupireddy
bharath.rupireddyforpostgres@gmail.com
In reply to: Tom Lane (#7)
Re: Inaccurate error message when set fdw batch_size to 0

On Mon, May 10, 2021 at 7:39 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:

Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> writes:

On Mon, May 10, 2021 at 12:00 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:

Yeah, this error message seems outright buggy. However, it's a minor
matter. Also, some people think "positive" is the same thing as
"non-negative", so maybe we need less ambiguous wording?

Since value 0 can't be considered as either a positive or negative
integer, I think we can do as following(roughly):

if (value < 0) "requires a zero or positive integer value"
if (value <= 0) "requires a positive integer value"

I was thinking of avoiding the passive voice and writing

"foo must be greater than zero"

+1 for "foo must be greater than zero" if (foo <= 0) kind of errors.
But, we also have some values for which zero is accepted, see below
error messages. How about the error message "foo must be greater than
or equal to zero"?

remainder for hash partition must be a non-negative integer
parallel vacuum degree must be a non-negative integer
repeat count size must be a non-negative integer
number of workers must be a non-negative integer
distance in phrase operator should be non-negative and less than %d

which removes all doubt. It's not necessary to keep the "integer"
aspect of the existing text, because if someone had supplied a
non-integer value, that would not have gotten this far anyway.

This led me to have a look at two postgres_fdw options: fetch_size and
batch_size, whether they accept positive non-integers like '123.456',
'789.123' and some unsound strings such as '100$%$#$#', '9,223,372,'.
It looks like yes, the truncated values 123. 789, 100, 9
(respectively) are accepted. This is because the way strtol is used to
fetch the integers from string. I'm not sure if that's intentional.
fetch_size = strtol(defGetString(def), NULL, 10);
batch_size = strtol(defGetString(def), NULL, 10);

I know that fetch_size and batch_size are "number of rows", so no
sensible users may specify values with fractional part or non integer
characters, but still we can fix this with the endptr parameter of
the strtol. Note that for the options fdw_startup_cost and
fdw_tuple_cost it's already fixed.

I'm thinking of starting a separate thread to discuss this, if this
thread is not the right place.

I'm not sure whether we should consider changing these messages:
remainder for hash partition must be a non-negative integer
parallel vacuum degree must be a non-negative integer
repeat count size must be a non-negative integer
number of workers must be a non-negative integer
%s requires a non-negative numeric value
distance in phrase operator should be non-negative and less than %d

I think for consistency it'd be good to change 'em all.

+1.

I'm almost tempted to put this matter into our message style guide too.

+1.

With Regards,
Bharath Rupireddy.
EnterpriseDB: http://www.enterprisedb.com

#10Amit Kapila
amit.kapila16@gmail.com
In reply to: Bharath Rupireddy (#9)
Re: Inaccurate error message when set fdw batch_size to 0

On Tue, May 11, 2021 at 11:28 AM Bharath Rupireddy
<bharath.rupireddyforpostgres@gmail.com> wrote:

On Mon, May 10, 2021 at 7:39 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:

Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> writes:

On Mon, May 10, 2021 at 12:00 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:

Yeah, this error message seems outright buggy. However, it's a minor
matter. Also, some people think "positive" is the same thing as
"non-negative", so maybe we need less ambiguous wording?

Since value 0 can't be considered as either a positive or negative
integer, I think we can do as following(roughly):

if (value < 0) "requires a zero or positive integer value"
if (value <= 0) "requires a positive integer value"

I was thinking of avoiding the passive voice and writing

"foo must be greater than zero"

+1 for "foo must be greater than zero" if (foo <= 0) kind of errors.
But, we also have some values for which zero is accepted, see below
error messages. How about the error message "foo must be greater than
or equal to zero"?

+1 for your proposed message for the cases where we have a check if
(foo < 0). Tom, Michael, do you see any problem with the proposed
message? We would like to make a similar change at another place [1]/messages/by-id/CALj2ACWGB9oHCR5ygkc8u6_QDqecObf9j2MxtOgsjZMMKsLj=Q@mail.gmail.com
so wanted to be consistent.

[1]: /messages/by-id/CALj2ACWGB9oHCR5ygkc8u6_QDqecObf9j2MxtOgsjZMMKsLj=Q@mail.gmail.com

--
With Regards,
Amit Kapila.

#11Bharath Rupireddy
bharath.rupireddyforpostgres@gmail.com
In reply to: Amit Kapila (#10)
1 attachment(s)
Re: Inaccurate error message when set fdw batch_size to 0

On Mon, May 17, 2021 at 4:23 PM Amit Kapila <amit.kapila16@gmail.com> wrote:

On Tue, May 11, 2021 at 11:28 AM Bharath Rupireddy
<bharath.rupireddyforpostgres@gmail.com> wrote:

On Mon, May 10, 2021 at 7:39 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:

Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> writes:

On Mon, May 10, 2021 at 12:00 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:

Yeah, this error message seems outright buggy. However, it's a minor
matter. Also, some people think "positive" is the same thing as
"non-negative", so maybe we need less ambiguous wording?

Since value 0 can't be considered as either a positive or negative
integer, I think we can do as following(roughly):

if (value < 0) "requires a zero or positive integer value"
if (value <= 0) "requires a positive integer value"

I was thinking of avoiding the passive voice and writing

"foo must be greater than zero"

+1 for "foo must be greater than zero" if (foo <= 0) kind of errors.
But, we also have some values for which zero is accepted, see below
error messages. How about the error message "foo must be greater than
or equal to zero"?

+1 for your proposed message for the cases where we have a check if
(foo < 0). Tom, Michael, do you see any problem with the proposed
message? We would like to make a similar change at another place [1]
so wanted to be consistent.

[1] - /messages/by-id/CALj2ACWGB9oHCR5ygkc8u6_QDqecObf9j2MxtOgsjZMMKsLj=Q@mail.gmail.com

Thanks all for your inputs. PSA v2 patch that uses the new convention.

With Regards,
Bharath Rupireddy.
EnterpriseDB: http://www.enterprisedb.com

Attachments:

v2-0001-Disambiguate-error-messages-that-use-non-negative.patchapplication/octet-stream; name=v2-0001-Disambiguate-error-messages-that-use-non-negative.patchDownload
From 50dd9a1ace63ad669055ad49a59a8df5f2dfe36e Mon Sep 17 00:00:00 2001
From: Bharath Rupireddy <bharath.rupireddy@enterprisedb.com>
Date: Wed, 19 May 2021 16:28:10 +0530
Subject: [PATCH v2] Disambiguate error messages that use "non-negative"

Using "non-negative" word in the error message looks ambiguous
since value 0 can't be considered as either a positive or negative
integer and some users might think "positive" is the same as
"non-negative". So, be clear with the following messages:
if (foo <= 0) then use "foo must be greater than zero" and
if (foo < 0) then use "foo must be greater than or equal to zero"

Also, added a note in the Error Message Style Guide to help writing
the new messages.

Authors: Hou Zhijie, Bharath Rupireddy.
---
 contrib/postgres_fdw/option.c           |  8 ++++----
 doc/src/sgml/sources.sgml               | 10 ++++++++++
 src/backend/access/transam/parallel.c   |  2 +-
 src/backend/partitioning/partbounds.c   |  4 ++--
 src/backend/utils/adt/tsquery_op.c      |  2 +-
 src/bin/scripts/vacuumdb.c              |  2 +-
 src/test/modules/test_shm_mq/test.c     | 10 +++++-----
 src/test/regress/expected/hash_part.out |  4 ++--
 8 files changed, 26 insertions(+), 16 deletions(-)

diff --git a/contrib/postgres_fdw/option.c b/contrib/postgres_fdw/option.c
index 672b55a808..69d60ed59f 100644
--- a/contrib/postgres_fdw/option.c
+++ b/contrib/postgres_fdw/option.c
@@ -118,7 +118,7 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
 		else if (strcmp(def->defname, "fdw_startup_cost") == 0 ||
 				 strcmp(def->defname, "fdw_tuple_cost") == 0)
 		{
-			/* these must have a non-negative numeric value */
+			/* these must have a positive numeric value */
 			double		val;
 			char	   *endp;
 
@@ -126,7 +126,7 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
 			if (*endp || val < 0)
 				ereport(ERROR,
 						(errcode(ERRCODE_SYNTAX_ERROR),
-						 errmsg("%s requires a non-negative numeric value",
+						 errmsg("%s must be greater than or equal to zero",
 								def->defname)));
 		}
 		else if (strcmp(def->defname, "extensions") == 0)
@@ -142,7 +142,7 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
 			if (fetch_size <= 0)
 				ereport(ERROR,
 						(errcode(ERRCODE_SYNTAX_ERROR),
-						 errmsg("%s requires a non-negative integer value",
+						 errmsg("%s must be greater than zero",
 								def->defname)));
 		}
 		else if (strcmp(def->defname, "batch_size") == 0)
@@ -153,7 +153,7 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
 			if (batch_size <= 0)
 				ereport(ERROR,
 						(errcode(ERRCODE_SYNTAX_ERROR),
-						 errmsg("%s requires a non-negative integer value",
+						 errmsg("%s must be greater than zero",
 								def->defname)));
 		}
 		else if (strcmp(def->defname, "password_required") == 0)
diff --git a/doc/src/sgml/sources.sgml b/doc/src/sgml/sources.sgml
index 3f2c40b750..dd70c0e597 100644
--- a/doc/src/sgml/sources.sgml
+++ b/doc/src/sgml/sources.sgml
@@ -880,6 +880,16 @@ BETTER: unrecognized node type: 42
    </para>
   </simplesect>
 
+  <simplesect>
+   <title>Avoid Using <quote>non-negative</quote> Word in Error Messages</title>
+
+   <para>
+    Do not use <quote>non-negative</quote> word in error messages as it looks
+    ambiguous. Instead, use <quote>foo must be greater than zero</quote> or 
+    <quote>foo must be greater than or equal to zero</quote>.
+   </para>
+  </simplesect>
+
   </sect1>
 
   <sect1 id="source-conventions">
diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c
index 3550ef13ba..0ed9990489 100644
--- a/src/backend/access/transam/parallel.c
+++ b/src/backend/access/transam/parallel.c
@@ -170,7 +170,7 @@ CreateParallelContext(const char *library_name, const char *function_name,
 	/* It is unsafe to create a parallel context if not in parallel mode. */
 	Assert(IsInParallelMode());
 
-	/* Number of workers should be non-negative. */
+	/* Number of workers should be greater than or equal to zero. */
 	Assert(nworkers >= 0);
 
 	/* We might be running in a short-lived memory context. */
diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c
index 7925fcce3b..69b8ef91fc 100644
--- a/src/backend/partitioning/partbounds.c
+++ b/src/backend/partitioning/partbounds.c
@@ -4698,11 +4698,11 @@ satisfies_hash_partition(PG_FUNCTION_ARGS)
 	if (modulus <= 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("modulus for hash partition must be a positive integer")));
+				 errmsg("modulus for hash partition must be greater than zero")));
 	if (remainder < 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("remainder for hash partition must be a non-negative integer")));
+				 errmsg("remainder for hash partition must be greater than or equal to zero")));
 	if (remainder >= modulus)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
diff --git a/src/backend/utils/adt/tsquery_op.c b/src/backend/utils/adt/tsquery_op.c
index 0575b55272..2f746cb2fa 100644
--- a/src/backend/utils/adt/tsquery_op.c
+++ b/src/backend/utils/adt/tsquery_op.c
@@ -121,7 +121,7 @@ tsquery_phrase_distance(PG_FUNCTION_ARGS)
 	if (distance < 0 || distance > MAXENTRYPOS)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("distance in phrase operator should be non-negative and less than %d",
+				 errmsg("distance in phrase operator must be greater than or equal to zero and less than %d",
 						MAXENTRYPOS)));
 	if (a->size == 0)
 	{
diff --git a/src/bin/scripts/vacuumdb.c b/src/bin/scripts/vacuumdb.c
index 7901c41f16..c197e76be5 100644
--- a/src/bin/scripts/vacuumdb.c
+++ b/src/bin/scripts/vacuumdb.c
@@ -200,7 +200,7 @@ main(int argc, char *argv[])
 				vacopts.parallel_workers = atoi(optarg);
 				if (vacopts.parallel_workers < 0)
 				{
-					pg_log_error("parallel vacuum degree must be a non-negative integer");
+					pg_log_error("parallel vacuum degree must be greater than or equal to zero");
 					exit(1);
 				}
 				break;
diff --git a/src/test/modules/test_shm_mq/test.c b/src/test/modules/test_shm_mq/test.c
index e5e32abac2..6cb7bb7c09 100644
--- a/src/test/modules/test_shm_mq/test.c
+++ b/src/test/modules/test_shm_mq/test.c
@@ -57,17 +57,17 @@ test_shm_mq(PG_FUNCTION_ARGS)
 	if (loop_count < 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("repeat count size must be a non-negative integer")));
+				 errmsg("repeat count size must be greater than or equal to zero")));
 
 	/*
 	 * Since this test sends data using the blocking interfaces, it cannot
 	 * send data to itself.  Therefore, a minimum of 1 worker is required. Of
 	 * course, a negative worker count is nonsensical.
 	 */
-	if (nworkers < 1)
+	if (nworkers <= 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("number of workers must be a positive integer")));
+				 errmsg("number of workers must be greater than zero")));
 
 	/* Set up dynamic shared memory segment and background workers. */
 	test_shm_mq_setup(queue_size, nworkers, &seg, &outqh, &inqh);
@@ -149,7 +149,7 @@ test_shm_mq_pipelined(PG_FUNCTION_ARGS)
 	if (loop_count < 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("repeat count size must be a non-negative integer")));
+				 errmsg("repeat count size must be greater than or equal to zero")));
 
 	/*
 	 * Using the nonblocking interfaces, we can even send data to ourselves,
@@ -158,7 +158,7 @@ test_shm_mq_pipelined(PG_FUNCTION_ARGS)
 	if (nworkers < 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("number of workers must be a non-negative integer")));
+				 errmsg("number of workers must be greater than or equal to zero")));
 
 	/* Set up dynamic shared memory segment and background workers. */
 	test_shm_mq_setup(queue_size, nworkers, &seg, &outqh, &inqh);
diff --git a/src/test/regress/expected/hash_part.out b/src/test/regress/expected/hash_part.out
index b79c2b44c1..987e55dc2e 100644
--- a/src/test/regress/expected/hash_part.out
+++ b/src/test/regress/expected/hash_part.out
@@ -19,10 +19,10 @@ SELECT satisfies_hash_partition('mchash1'::regclass, 4, 0, NULL);
 ERROR:  "mchash1" is not a hash partitioned table
 -- invalid modulus
 SELECT satisfies_hash_partition('mchash'::regclass, 0, 0, NULL);
-ERROR:  modulus for hash partition must be a positive integer
+ERROR:  modulus for hash partition must be greater than zero
 -- remainder too small
 SELECT satisfies_hash_partition('mchash'::regclass, 1, -1, NULL);
-ERROR:  remainder for hash partition must be a non-negative integer
+ERROR:  remainder for hash partition must be greater than or equal to zero
 -- remainder too large
 SELECT satisfies_hash_partition('mchash'::regclass, 1, 1, NULL);
 ERROR:  remainder for hash partition must be less than modulus
-- 
2.25.1

#12Fujii Masao
masao.fujii@oss.nttdata.com
In reply to: Bharath Rupireddy (#11)
Re: Inaccurate error message when set fdw batch_size to 0

On 2021/05/19 20:01, Bharath Rupireddy wrote:

On Mon, May 17, 2021 at 4:23 PM Amit Kapila <amit.kapila16@gmail.com> wrote:

On Tue, May 11, 2021 at 11:28 AM Bharath Rupireddy
<bharath.rupireddyforpostgres@gmail.com> wrote:

On Mon, May 10, 2021 at 7:39 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:

Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> writes:

On Mon, May 10, 2021 at 12:00 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:

Yeah, this error message seems outright buggy. However, it's a minor
matter. Also, some people think "positive" is the same thing as
"non-negative", so maybe we need less ambiguous wording?

Since value 0 can't be considered as either a positive or negative
integer, I think we can do as following(roughly):

if (value < 0) "requires a zero or positive integer value"
if (value <= 0) "requires a positive integer value"

I was thinking of avoiding the passive voice and writing

"foo must be greater than zero"

+1 for "foo must be greater than zero" if (foo <= 0) kind of errors.
But, we also have some values for which zero is accepted, see below
error messages. How about the error message "foo must be greater than
or equal to zero"?

+1 for your proposed message for the cases where we have a check if
(foo < 0). Tom, Michael, do you see any problem with the proposed
message? We would like to make a similar change at another place [1]
so wanted to be consistent.

[1] - /messages/by-id/CALj2ACWGB9oHCR5ygkc8u6_QDqecObf9j2MxtOgsjZMMKsLj=Q@mail.gmail.com

Thanks all for your inputs. PSA v2 patch that uses the new convention.

Thanks for the patch!

  				ereport(ERROR,
  						(errcode(ERRCODE_SYNTAX_ERROR),
-						 errmsg("%s requires a non-negative numeric value",
+						 errmsg("%s must be greater than or equal to zero",
  								def->defname)));
  		}
  		else if (strcmp(def->defname, "extensions") == 0)
@@ -142,7 +142,7 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
  			if (fetch_size <= 0)
  				ereport(ERROR,
  						(errcode(ERRCODE_SYNTAX_ERROR),
-						 errmsg("%s requires a non-negative integer value",
+						 errmsg("%s must be greater than zero",

I'm fine to convert "non-negative" word to "greater than" or "greater than
or equal to" in the messages. But this change also seems to get rid of
the information about the data type of the option from the message.
I'm not sure if this is an improvement. Probably isn't it better to
convert "requires a non-negative integer value" to "must be an integer value
greater than zero"?

Regards,

--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION

#13Bharath Rupireddy
bharath.rupireddyforpostgres@gmail.com
In reply to: Fujii Masao (#12)
1 attachment(s)
Re: Inaccurate error message when set fdw batch_size to 0

On Wed, May 19, 2021 at 5:20 PM Fujii Masao <masao.fujii@oss.nttdata.com> wrote:

ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
-                                                errmsg("%s requires a non-negative numeric value",
+                                                errmsg("%s must be greater than or equal to zero",
def->defname)));
}
else if (strcmp(def->defname, "extensions") == 0)
@@ -142,7 +142,7 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
if (fetch_size <= 0)
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
-                                                errmsg("%s requires a non-negative integer value",
+                                                errmsg("%s must be greater than zero",

I'm fine to convert "non-negative" word to "greater than" or "greater than
or equal to" in the messages. But this change also seems to get rid of
the information about the data type of the option from the message.
I'm not sure if this is an improvement. Probably isn't it better to
convert "requires a non-negative integer value" to "must be an integer value
greater than zero"?

Thanks for the comments. Done that way. PSA v3 patch.

With Regards,
Bharath Rupireddy.
EnterpriseDB: http://www.enterprisedb.com

Attachments:

v3-0001-Disambiguate-error-messages-that-use-non-negative.patchapplication/octet-stream; name=v3-0001-Disambiguate-error-messages-that-use-non-negative.patchDownload
From 3067c1bb476c6293de957e0a5fc4ec1c8f8727c1 Mon Sep 17 00:00:00 2001
From: Bharath Rupireddy <bharath.rupireddy@enterprisedb.com>
Date: Wed, 19 May 2021 21:47:53 +0530
Subject: [PATCH v3] Disambiguate error messages that use "non-negative"

Using "non-negative" word in the error message looks ambiguous
since value 0 can't be considered as either a positive or negative
integer and some users might think "positive" is the same as
"non-negative". So, be clear with the following messages:
if (foo <= 0) then use "foo must be greater than zero" and
if (foo < 0) then use "foo must be greater than or equal to zero"

Also, added a note in the Error Message Style Guide to help writing
the new messages.

Authors: Hou Zhijie, Bharath Rupireddy.
---
 contrib/postgres_fdw/option.c           |  8 ++++----
 doc/src/sgml/sources.sgml               | 14 ++++++++++++++
 src/backend/access/transam/parallel.c   |  1 -
 src/backend/partitioning/partbounds.c   |  4 ++--
 src/backend/utils/adt/tsquery_op.c      |  2 +-
 src/bin/scripts/vacuumdb.c              |  2 +-
 src/test/modules/test_shm_mq/test.c     | 10 +++++-----
 src/test/regress/expected/hash_part.out |  4 ++--
 8 files changed, 29 insertions(+), 16 deletions(-)

diff --git a/contrib/postgres_fdw/option.c b/contrib/postgres_fdw/option.c
index 672b55a808..a0d771a16b 100644
--- a/contrib/postgres_fdw/option.c
+++ b/contrib/postgres_fdw/option.c
@@ -118,7 +118,7 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
 		else if (strcmp(def->defname, "fdw_startup_cost") == 0 ||
 				 strcmp(def->defname, "fdw_tuple_cost") == 0)
 		{
-			/* these must have a non-negative numeric value */
+			/* these must have a positive numeric value */
 			double		val;
 			char	   *endp;
 
@@ -126,7 +126,7 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
 			if (*endp || val < 0)
 				ereport(ERROR,
 						(errcode(ERRCODE_SYNTAX_ERROR),
-						 errmsg("%s requires a non-negative numeric value",
+						 errmsg("\"%s\" must be a numeric value greater than or equal to zero",
 								def->defname)));
 		}
 		else if (strcmp(def->defname, "extensions") == 0)
@@ -142,7 +142,7 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
 			if (fetch_size <= 0)
 				ereport(ERROR,
 						(errcode(ERRCODE_SYNTAX_ERROR),
-						 errmsg("%s requires a non-negative integer value",
+						 errmsg("\"%s\" must be an integer value greater than zero",
 								def->defname)));
 		}
 		else if (strcmp(def->defname, "batch_size") == 0)
@@ -153,7 +153,7 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
 			if (batch_size <= 0)
 				ereport(ERROR,
 						(errcode(ERRCODE_SYNTAX_ERROR),
-						 errmsg("%s requires a non-negative integer value",
+						 errmsg("\"%s\" must be an integer value greater than zero",
 								def->defname)));
 		}
 		else if (strcmp(def->defname, "password_required") == 0)
diff --git a/doc/src/sgml/sources.sgml b/doc/src/sgml/sources.sgml
index 3f2c40b750..b9c632a349 100644
--- a/doc/src/sgml/sources.sgml
+++ b/doc/src/sgml/sources.sgml
@@ -880,6 +880,20 @@ BETTER: unrecognized node type: 42
    </para>
   </simplesect>
 
+  <simplesect>
+   <title>Avoid Using <quote>non-negative</quote> Word in Error Messages</title>
+
+   <para>
+    Do not use <quote>non-negative</quote> word in error messages as it looks
+    ambiguous. Instead, use <quote>foo must be an integer value greater than zero</quote> or 
+    <quote>foo must be an integer value greater than or equal to zero</quote>
+    if option <quote>foo</quote> expects an integer value. Use
+    <quote>foo must be a numeric value greater than zero</quote> or
+    <quote>foo must be a numeric value greater than or equal to zero</quote>
+    if option <quote>foo</quote> expects a numeric value
+   </para>
+  </simplesect>
+
   </sect1>
 
   <sect1 id="source-conventions">
diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c
index 3550ef13ba..cb978845fe 100644
--- a/src/backend/access/transam/parallel.c
+++ b/src/backend/access/transam/parallel.c
@@ -170,7 +170,6 @@ CreateParallelContext(const char *library_name, const char *function_name,
 	/* It is unsafe to create a parallel context if not in parallel mode. */
 	Assert(IsInParallelMode());
 
-	/* Number of workers should be non-negative. */
 	Assert(nworkers >= 0);
 
 	/* We might be running in a short-lived memory context. */
diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c
index 7925fcce3b..ac4ae65189 100644
--- a/src/backend/partitioning/partbounds.c
+++ b/src/backend/partitioning/partbounds.c
@@ -4698,11 +4698,11 @@ satisfies_hash_partition(PG_FUNCTION_ARGS)
 	if (modulus <= 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("modulus for hash partition must be a positive integer")));
+				 errmsg("modulus for hash partition must be an integer value greater than zero")));
 	if (remainder < 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("remainder for hash partition must be a non-negative integer")));
+				 errmsg("remainder for hash partition must be an integer value greater than or equal to zero")));
 	if (remainder >= modulus)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
diff --git a/src/backend/utils/adt/tsquery_op.c b/src/backend/utils/adt/tsquery_op.c
index 0575b55272..20b9a6f176 100644
--- a/src/backend/utils/adt/tsquery_op.c
+++ b/src/backend/utils/adt/tsquery_op.c
@@ -121,7 +121,7 @@ tsquery_phrase_distance(PG_FUNCTION_ARGS)
 	if (distance < 0 || distance > MAXENTRYPOS)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("distance in phrase operator should be non-negative and less than %d",
+				 errmsg("distance in phrase operator must be an integer value greater than or equal to zero and less than %d",
 						MAXENTRYPOS)));
 	if (a->size == 0)
 	{
diff --git a/src/bin/scripts/vacuumdb.c b/src/bin/scripts/vacuumdb.c
index 7901c41f16..3434ce2793 100644
--- a/src/bin/scripts/vacuumdb.c
+++ b/src/bin/scripts/vacuumdb.c
@@ -200,7 +200,7 @@ main(int argc, char *argv[])
 				vacopts.parallel_workers = atoi(optarg);
 				if (vacopts.parallel_workers < 0)
 				{
-					pg_log_error("parallel vacuum degree must be a non-negative integer");
+					pg_log_error("parallel vacuum degree must be an integer value greater than or equal to zero");
 					exit(1);
 				}
 				break;
diff --git a/src/test/modules/test_shm_mq/test.c b/src/test/modules/test_shm_mq/test.c
index e5e32abac2..8867ba4e6b 100644
--- a/src/test/modules/test_shm_mq/test.c
+++ b/src/test/modules/test_shm_mq/test.c
@@ -57,17 +57,17 @@ test_shm_mq(PG_FUNCTION_ARGS)
 	if (loop_count < 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("repeat count size must be a non-negative integer")));
+				 errmsg("repeat count size must be an integer value greater than or equal to zero")));
 
 	/*
 	 * Since this test sends data using the blocking interfaces, it cannot
 	 * send data to itself.  Therefore, a minimum of 1 worker is required. Of
 	 * course, a negative worker count is nonsensical.
 	 */
-	if (nworkers < 1)
+	if (nworkers <= 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("number of workers must be a positive integer")));
+				 errmsg("number of workers must be an integer value greater than zero")));
 
 	/* Set up dynamic shared memory segment and background workers. */
 	test_shm_mq_setup(queue_size, nworkers, &seg, &outqh, &inqh);
@@ -149,7 +149,7 @@ test_shm_mq_pipelined(PG_FUNCTION_ARGS)
 	if (loop_count < 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("repeat count size must be a non-negative integer")));
+				 errmsg("repeat count size must be greater than or equal to zero")));
 
 	/*
 	 * Using the nonblocking interfaces, we can even send data to ourselves,
@@ -158,7 +158,7 @@ test_shm_mq_pipelined(PG_FUNCTION_ARGS)
 	if (nworkers < 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("number of workers must be a non-negative integer")));
+				 errmsg("number of workers must be greater than or equal to zero")));
 
 	/* Set up dynamic shared memory segment and background workers. */
 	test_shm_mq_setup(queue_size, nworkers, &seg, &outqh, &inqh);
diff --git a/src/test/regress/expected/hash_part.out b/src/test/regress/expected/hash_part.out
index b79c2b44c1..ac3aabee02 100644
--- a/src/test/regress/expected/hash_part.out
+++ b/src/test/regress/expected/hash_part.out
@@ -19,10 +19,10 @@ SELECT satisfies_hash_partition('mchash1'::regclass, 4, 0, NULL);
 ERROR:  "mchash1" is not a hash partitioned table
 -- invalid modulus
 SELECT satisfies_hash_partition('mchash'::regclass, 0, 0, NULL);
-ERROR:  modulus for hash partition must be a positive integer
+ERROR:  modulus for hash partition must be an integer value greater than zero
 -- remainder too small
 SELECT satisfies_hash_partition('mchash'::regclass, 1, -1, NULL);
-ERROR:  remainder for hash partition must be a non-negative integer
+ERROR:  remainder for hash partition must be an integer value greater than or equal to zero
 -- remainder too large
 SELECT satisfies_hash_partition('mchash'::regclass, 1, 1, NULL);
 ERROR:  remainder for hash partition must be less than modulus
-- 
2.25.1

#14Kyotaro Horiguchi
horikyota.ntt@gmail.com
In reply to: Bharath Rupireddy (#13)
Re: Inaccurate error message when set fdw batch_size to 0

At Wed, 19 May 2021 21:48:56 +0530, Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> wrote in

On Wed, May 19, 2021 at 5:20 PM Fujii Masao <masao.fujii@oss.nttdata.com> wrote:

I'm fine to convert "non-negative" word to "greater than" or "greater than
or equal to" in the messages. But this change also seems to get rid of
the information about the data type of the option from the message.
I'm not sure if this is an improvement. Probably isn't it better to
convert "requires a non-negative integer value" to "must be an integer value
greater than zero"?

Thanks for the comments. Done that way. PSA v3 patch.

--- a/src/backend/utils/adt/tsquery_op.c
+++ b/src/backend/utils/adt/tsquery_op.c
@@ -121,7 +121,7 @@ tsquery_phrase_distance(PG_FUNCTION_ARGS)
 	if (distance < 0 || distance > MAXENTRYPOS)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("distance in phrase operator should be non-negative and less than %d",
+				 errmsg("distance in phrase operator must be an integer value greater than or equal to zero and less than %d",
 						MAXENTRYPOS)));

Though it is not due to this patch, but the message looks wrong. The condition is suggesting:

"distance in phrase operator must be an integer value greater than or equal to zero and less than or equal to %d"

I'm not sure readers can read it without biting their tongue. How
about something like the following instead?

"distance in phrase operator must be an integer value between zero and
%d inclusive."

regards.

--
Kyotaro Horiguchi
NTT Open Source Software Center

#15Bharath Rupireddy
bharath.rupireddyforpostgres@gmail.com
In reply to: Kyotaro Horiguchi (#14)
1 attachment(s)
Re: Inaccurate error message when set fdw batch_size to 0

On Thu, May 20, 2021 at 1:44 PM Kyotaro Horiguchi
<horikyota.ntt@gmail.com> wrote:

At Wed, 19 May 2021 21:48:56 +0530, Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> wrote in

On Wed, May 19, 2021 at 5:20 PM Fujii Masao <masao.fujii@oss.nttdata.com> wrote:

I'm fine to convert "non-negative" word to "greater than" or "greater than
or equal to" in the messages. But this change also seems to get rid of
the information about the data type of the option from the message.
I'm not sure if this is an improvement. Probably isn't it better to
convert "requires a non-negative integer value" to "must be an integer value
greater than zero"?

Thanks for the comments. Done that way. PSA v3 patch.

--- a/src/backend/utils/adt/tsquery_op.c
+++ b/src/backend/utils/adt/tsquery_op.c
@@ -121,7 +121,7 @@ tsquery_phrase_distance(PG_FUNCTION_ARGS)
if (distance < 0 || distance > MAXENTRYPOS)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-                                errmsg("distance in phrase operator should be non-negative and less than %d",
+                                errmsg("distance in phrase operator must be an integer value greater than or equal to zero and less than %d",
MAXENTRYPOS)));

Though it is not due to this patch, but the message looks wrong. The condition is suggesting:

"distance in phrase operator must be an integer value greater than or equal to zero and less than or equal to %d"

I'm not sure readers can read it without biting their tongue. How
about something like the following instead?

"distance in phrase operator must be an integer value between zero and
%d inclusive."

Thanks. That looks better. PSA v4 patch.

With Regards,
Bharath Rupireddy.
EnterpriseDB: http://www.enterprisedb.com

Attachments:

v4-0001-Disambiguate-error-messages-that-use-non-negative.patchapplication/x-patch; name=v4-0001-Disambiguate-error-messages-that-use-non-negative.patchDownload
From 3dea08a9f6a0a39ea48ea2db67791d46db7997a9 Mon Sep 17 00:00:00 2001
From: Bharath Rupireddy <bharath.rupireddy@enterprisedb.com>
Date: Thu, 20 May 2021 14:23:03 +0530
Subject: [PATCH v4] Disambiguate error messages that use "non-negative"

Using "non-negative" word in the error message looks ambiguous
since value 0 can't be considered as either a positive or negative
integer and some users might think "positive" is the same as
"non-negative". So, be clear with the following messages:
if (foo <= 0) then use "foo must be greater than zero" and
if (foo < 0) then use "foo must be greater than or equal to zero"

Also, added a note in the Error Message Style Guide to help writing
the new messages.

Authors: Hou Zhijie, Bharath Rupireddy.
---
 contrib/postgres_fdw/option.c           |  8 ++++----
 doc/src/sgml/sources.sgml               | 14 ++++++++++++++
 src/backend/access/transam/parallel.c   |  1 -
 src/backend/partitioning/partbounds.c   |  4 ++--
 src/backend/utils/adt/tsquery_op.c      |  2 +-
 src/bin/scripts/vacuumdb.c              |  2 +-
 src/test/modules/test_shm_mq/test.c     | 10 +++++-----
 src/test/regress/expected/hash_part.out |  4 ++--
 8 files changed, 29 insertions(+), 16 deletions(-)

diff --git a/contrib/postgres_fdw/option.c b/contrib/postgres_fdw/option.c
index 672b55a808..a0d771a16b 100644
--- a/contrib/postgres_fdw/option.c
+++ b/contrib/postgres_fdw/option.c
@@ -118,7 +118,7 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
 		else if (strcmp(def->defname, "fdw_startup_cost") == 0 ||
 				 strcmp(def->defname, "fdw_tuple_cost") == 0)
 		{
-			/* these must have a non-negative numeric value */
+			/* these must have a positive numeric value */
 			double		val;
 			char	   *endp;
 
@@ -126,7 +126,7 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
 			if (*endp || val < 0)
 				ereport(ERROR,
 						(errcode(ERRCODE_SYNTAX_ERROR),
-						 errmsg("%s requires a non-negative numeric value",
+						 errmsg("\"%s\" must be a numeric value greater than or equal to zero",
 								def->defname)));
 		}
 		else if (strcmp(def->defname, "extensions") == 0)
@@ -142,7 +142,7 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
 			if (fetch_size <= 0)
 				ereport(ERROR,
 						(errcode(ERRCODE_SYNTAX_ERROR),
-						 errmsg("%s requires a non-negative integer value",
+						 errmsg("\"%s\" must be an integer value greater than zero",
 								def->defname)));
 		}
 		else if (strcmp(def->defname, "batch_size") == 0)
@@ -153,7 +153,7 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
 			if (batch_size <= 0)
 				ereport(ERROR,
 						(errcode(ERRCODE_SYNTAX_ERROR),
-						 errmsg("%s requires a non-negative integer value",
+						 errmsg("\"%s\" must be an integer value greater than zero",
 								def->defname)));
 		}
 		else if (strcmp(def->defname, "password_required") == 0)
diff --git a/doc/src/sgml/sources.sgml b/doc/src/sgml/sources.sgml
index 3f2c40b750..b9c632a349 100644
--- a/doc/src/sgml/sources.sgml
+++ b/doc/src/sgml/sources.sgml
@@ -880,6 +880,20 @@ BETTER: unrecognized node type: 42
    </para>
   </simplesect>
 
+  <simplesect>
+   <title>Avoid Using <quote>non-negative</quote> Word in Error Messages</title>
+
+   <para>
+    Do not use <quote>non-negative</quote> word in error messages as it looks
+    ambiguous. Instead, use <quote>foo must be an integer value greater than zero</quote> or 
+    <quote>foo must be an integer value greater than or equal to zero</quote>
+    if option <quote>foo</quote> expects an integer value. Use
+    <quote>foo must be a numeric value greater than zero</quote> or
+    <quote>foo must be a numeric value greater than or equal to zero</quote>
+    if option <quote>foo</quote> expects a numeric value
+   </para>
+  </simplesect>
+
   </sect1>
 
   <sect1 id="source-conventions">
diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c
index 3550ef13ba..cb978845fe 100644
--- a/src/backend/access/transam/parallel.c
+++ b/src/backend/access/transam/parallel.c
@@ -170,7 +170,6 @@ CreateParallelContext(const char *library_name, const char *function_name,
 	/* It is unsafe to create a parallel context if not in parallel mode. */
 	Assert(IsInParallelMode());
 
-	/* Number of workers should be non-negative. */
 	Assert(nworkers >= 0);
 
 	/* We might be running in a short-lived memory context. */
diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c
index 7925fcce3b..ac4ae65189 100644
--- a/src/backend/partitioning/partbounds.c
+++ b/src/backend/partitioning/partbounds.c
@@ -4698,11 +4698,11 @@ satisfies_hash_partition(PG_FUNCTION_ARGS)
 	if (modulus <= 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("modulus for hash partition must be a positive integer")));
+				 errmsg("modulus for hash partition must be an integer value greater than zero")));
 	if (remainder < 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("remainder for hash partition must be a non-negative integer")));
+				 errmsg("remainder for hash partition must be an integer value greater than or equal to zero")));
 	if (remainder >= modulus)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
diff --git a/src/backend/utils/adt/tsquery_op.c b/src/backend/utils/adt/tsquery_op.c
index 0575b55272..8211e6c9bc 100644
--- a/src/backend/utils/adt/tsquery_op.c
+++ b/src/backend/utils/adt/tsquery_op.c
@@ -121,7 +121,7 @@ tsquery_phrase_distance(PG_FUNCTION_ARGS)
 	if (distance < 0 || distance > MAXENTRYPOS)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("distance in phrase operator should be non-negative and less than %d",
+				 errmsg("distance in phrase operator must be an integer value between zero and %d inclusive",
 						MAXENTRYPOS)));
 	if (a->size == 0)
 	{
diff --git a/src/bin/scripts/vacuumdb.c b/src/bin/scripts/vacuumdb.c
index 7901c41f16..3434ce2793 100644
--- a/src/bin/scripts/vacuumdb.c
+++ b/src/bin/scripts/vacuumdb.c
@@ -200,7 +200,7 @@ main(int argc, char *argv[])
 				vacopts.parallel_workers = atoi(optarg);
 				if (vacopts.parallel_workers < 0)
 				{
-					pg_log_error("parallel vacuum degree must be a non-negative integer");
+					pg_log_error("parallel vacuum degree must be an integer value greater than or equal to zero");
 					exit(1);
 				}
 				break;
diff --git a/src/test/modules/test_shm_mq/test.c b/src/test/modules/test_shm_mq/test.c
index e5e32abac2..8867ba4e6b 100644
--- a/src/test/modules/test_shm_mq/test.c
+++ b/src/test/modules/test_shm_mq/test.c
@@ -57,17 +57,17 @@ test_shm_mq(PG_FUNCTION_ARGS)
 	if (loop_count < 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("repeat count size must be a non-negative integer")));
+				 errmsg("repeat count size must be an integer value greater than or equal to zero")));
 
 	/*
 	 * Since this test sends data using the blocking interfaces, it cannot
 	 * send data to itself.  Therefore, a minimum of 1 worker is required. Of
 	 * course, a negative worker count is nonsensical.
 	 */
-	if (nworkers < 1)
+	if (nworkers <= 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("number of workers must be a positive integer")));
+				 errmsg("number of workers must be an integer value greater than zero")));
 
 	/* Set up dynamic shared memory segment and background workers. */
 	test_shm_mq_setup(queue_size, nworkers, &seg, &outqh, &inqh);
@@ -149,7 +149,7 @@ test_shm_mq_pipelined(PG_FUNCTION_ARGS)
 	if (loop_count < 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("repeat count size must be a non-negative integer")));
+				 errmsg("repeat count size must be greater than or equal to zero")));
 
 	/*
 	 * Using the nonblocking interfaces, we can even send data to ourselves,
@@ -158,7 +158,7 @@ test_shm_mq_pipelined(PG_FUNCTION_ARGS)
 	if (nworkers < 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("number of workers must be a non-negative integer")));
+				 errmsg("number of workers must be greater than or equal to zero")));
 
 	/* Set up dynamic shared memory segment and background workers. */
 	test_shm_mq_setup(queue_size, nworkers, &seg, &outqh, &inqh);
diff --git a/src/test/regress/expected/hash_part.out b/src/test/regress/expected/hash_part.out
index b79c2b44c1..ac3aabee02 100644
--- a/src/test/regress/expected/hash_part.out
+++ b/src/test/regress/expected/hash_part.out
@@ -19,10 +19,10 @@ SELECT satisfies_hash_partition('mchash1'::regclass, 4, 0, NULL);
 ERROR:  "mchash1" is not a hash partitioned table
 -- invalid modulus
 SELECT satisfies_hash_partition('mchash'::regclass, 0, 0, NULL);
-ERROR:  modulus for hash partition must be a positive integer
+ERROR:  modulus for hash partition must be an integer value greater than zero
 -- remainder too small
 SELECT satisfies_hash_partition('mchash'::regclass, 1, -1, NULL);
-ERROR:  remainder for hash partition must be a non-negative integer
+ERROR:  remainder for hash partition must be an integer value greater than or equal to zero
 -- remainder too large
 SELECT satisfies_hash_partition('mchash'::regclass, 1, 1, NULL);
 ERROR:  remainder for hash partition must be less than modulus
-- 
2.25.1

#16Bharath Rupireddy
bharath.rupireddyforpostgres@gmail.com
In reply to: Bharath Rupireddy (#15)
1 attachment(s)
Re: Inaccurate error message when set fdw batch_size to 0

On Thu, May 20, 2021 at 2:43 PM Bharath Rupireddy
<bharath.rupireddyforpostgres@gmail.com> wrote:

Thanks. That looks better. PSA v4 patch.

Attaching v5 patch rebased on latest master.

With Regards,
Bharath Rupireddy.
EnterpriseDB: http://www.enterprisedb.com

Attachments:

v5-0001-Disambiguate-error-messages-that-use-non-negative.patchapplication/octet-stream; name=v5-0001-Disambiguate-error-messages-that-use-non-negative.patchDownload
From 492126340f3bb3ab3a89ff04a8b8f4b6fcdb767b Mon Sep 17 00:00:00 2001
From: Bharath Rupireddy <bharath.rupireddy@enterprisedb.com>
Date: Wed, 26 May 2021 11:50:42 +0530
Subject: [PATCH v5] Disambiguate error messages that use "non-negative"

Using "non-negative" word in the error message looks ambiguous
since value 0 can't be considered as either a positive or negative
integer and some users might think "positive" is the same as
"non-negative". So, be clear with the following messages:
if (foo <= 0) then use "foo must be greater than zero" and
if (foo < 0) then use "foo must be greater than or equal to zero"

Also, added a note in the Error Message Style Guide to help writing
the new messages.

Authors: Hou Zhijie, Bharath Rupireddy.
---
 contrib/postgres_fdw/option.c           |  8 ++++----
 doc/src/sgml/sources.sgml               | 14 ++++++++++++++
 src/backend/access/transam/parallel.c   |  1 -
 src/backend/partitioning/partbounds.c   |  4 ++--
 src/backend/utils/adt/tsquery_op.c      |  2 +-
 src/bin/scripts/vacuumdb.c              |  2 +-
 src/test/modules/test_shm_mq/test.c     | 10 +++++-----
 src/test/regress/expected/hash_part.out |  4 ++--
 8 files changed, 29 insertions(+), 16 deletions(-)

diff --git a/contrib/postgres_fdw/option.c b/contrib/postgres_fdw/option.c
index 672b55a808..a0d771a16b 100644
--- a/contrib/postgres_fdw/option.c
+++ b/contrib/postgres_fdw/option.c
@@ -118,7 +118,7 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
 		else if (strcmp(def->defname, "fdw_startup_cost") == 0 ||
 				 strcmp(def->defname, "fdw_tuple_cost") == 0)
 		{
-			/* these must have a non-negative numeric value */
+			/* these must have a positive numeric value */
 			double		val;
 			char	   *endp;
 
@@ -126,7 +126,7 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
 			if (*endp || val < 0)
 				ereport(ERROR,
 						(errcode(ERRCODE_SYNTAX_ERROR),
-						 errmsg("%s requires a non-negative numeric value",
+						 errmsg("\"%s\" must be a numeric value greater than or equal to zero",
 								def->defname)));
 		}
 		else if (strcmp(def->defname, "extensions") == 0)
@@ -142,7 +142,7 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
 			if (fetch_size <= 0)
 				ereport(ERROR,
 						(errcode(ERRCODE_SYNTAX_ERROR),
-						 errmsg("%s requires a non-negative integer value",
+						 errmsg("\"%s\" must be an integer value greater than zero",
 								def->defname)));
 		}
 		else if (strcmp(def->defname, "batch_size") == 0)
@@ -153,7 +153,7 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
 			if (batch_size <= 0)
 				ereport(ERROR,
 						(errcode(ERRCODE_SYNTAX_ERROR),
-						 errmsg("%s requires a non-negative integer value",
+						 errmsg("\"%s\" must be an integer value greater than zero",
 								def->defname)));
 		}
 		else if (strcmp(def->defname, "password_required") == 0)
diff --git a/doc/src/sgml/sources.sgml b/doc/src/sgml/sources.sgml
index 3f2c40b750..b9c632a349 100644
--- a/doc/src/sgml/sources.sgml
+++ b/doc/src/sgml/sources.sgml
@@ -880,6 +880,20 @@ BETTER: unrecognized node type: 42
    </para>
   </simplesect>
 
+  <simplesect>
+   <title>Avoid Using <quote>non-negative</quote> Word in Error Messages</title>
+
+   <para>
+    Do not use <quote>non-negative</quote> word in error messages as it looks
+    ambiguous. Instead, use <quote>foo must be an integer value greater than zero</quote> or 
+    <quote>foo must be an integer value greater than or equal to zero</quote>
+    if option <quote>foo</quote> expects an integer value. Use
+    <quote>foo must be a numeric value greater than zero</quote> or
+    <quote>foo must be a numeric value greater than or equal to zero</quote>
+    if option <quote>foo</quote> expects a numeric value
+   </para>
+  </simplesect>
+
   </sect1>
 
   <sect1 id="source-conventions">
diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c
index 3550ef13ba..cb978845fe 100644
--- a/src/backend/access/transam/parallel.c
+++ b/src/backend/access/transam/parallel.c
@@ -170,7 +170,6 @@ CreateParallelContext(const char *library_name, const char *function_name,
 	/* It is unsafe to create a parallel context if not in parallel mode. */
 	Assert(IsInParallelMode());
 
-	/* Number of workers should be non-negative. */
 	Assert(nworkers >= 0);
 
 	/* We might be running in a short-lived memory context. */
diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c
index 7925fcce3b..ac4ae65189 100644
--- a/src/backend/partitioning/partbounds.c
+++ b/src/backend/partitioning/partbounds.c
@@ -4698,11 +4698,11 @@ satisfies_hash_partition(PG_FUNCTION_ARGS)
 	if (modulus <= 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("modulus for hash partition must be a positive integer")));
+				 errmsg("modulus for hash partition must be an integer value greater than zero")));
 	if (remainder < 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("remainder for hash partition must be a non-negative integer")));
+				 errmsg("remainder for hash partition must be an integer value greater than or equal to zero")));
 	if (remainder >= modulus)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
diff --git a/src/backend/utils/adt/tsquery_op.c b/src/backend/utils/adt/tsquery_op.c
index 0575b55272..8211e6c9bc 100644
--- a/src/backend/utils/adt/tsquery_op.c
+++ b/src/backend/utils/adt/tsquery_op.c
@@ -121,7 +121,7 @@ tsquery_phrase_distance(PG_FUNCTION_ARGS)
 	if (distance < 0 || distance > MAXENTRYPOS)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("distance in phrase operator should be non-negative and less than %d",
+				 errmsg("distance in phrase operator must be an integer value between zero and %d inclusive",
 						MAXENTRYPOS)));
 	if (a->size == 0)
 	{
diff --git a/src/bin/scripts/vacuumdb.c b/src/bin/scripts/vacuumdb.c
index 069a861aab..3add651559 100644
--- a/src/bin/scripts/vacuumdb.c
+++ b/src/bin/scripts/vacuumdb.c
@@ -200,7 +200,7 @@ main(int argc, char *argv[])
 				vacopts.parallel_workers = atoi(optarg);
 				if (vacopts.parallel_workers < 0)
 				{
-					pg_log_error("parallel workers for vacuum must be greater than or equal to zero");
+					pg_log_error("parallel workers for vacuum must be an integer value greater than or equal to zero");
 					exit(1);
 				}
 				break;
diff --git a/src/test/modules/test_shm_mq/test.c b/src/test/modules/test_shm_mq/test.c
index e5e32abac2..8867ba4e6b 100644
--- a/src/test/modules/test_shm_mq/test.c
+++ b/src/test/modules/test_shm_mq/test.c
@@ -57,17 +57,17 @@ test_shm_mq(PG_FUNCTION_ARGS)
 	if (loop_count < 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("repeat count size must be a non-negative integer")));
+				 errmsg("repeat count size must be an integer value greater than or equal to zero")));
 
 	/*
 	 * Since this test sends data using the blocking interfaces, it cannot
 	 * send data to itself.  Therefore, a minimum of 1 worker is required. Of
 	 * course, a negative worker count is nonsensical.
 	 */
-	if (nworkers < 1)
+	if (nworkers <= 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("number of workers must be a positive integer")));
+				 errmsg("number of workers must be an integer value greater than zero")));
 
 	/* Set up dynamic shared memory segment and background workers. */
 	test_shm_mq_setup(queue_size, nworkers, &seg, &outqh, &inqh);
@@ -149,7 +149,7 @@ test_shm_mq_pipelined(PG_FUNCTION_ARGS)
 	if (loop_count < 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("repeat count size must be a non-negative integer")));
+				 errmsg("repeat count size must be greater than or equal to zero")));
 
 	/*
 	 * Using the nonblocking interfaces, we can even send data to ourselves,
@@ -158,7 +158,7 @@ test_shm_mq_pipelined(PG_FUNCTION_ARGS)
 	if (nworkers < 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("number of workers must be a non-negative integer")));
+				 errmsg("number of workers must be greater than or equal to zero")));
 
 	/* Set up dynamic shared memory segment and background workers. */
 	test_shm_mq_setup(queue_size, nworkers, &seg, &outqh, &inqh);
diff --git a/src/test/regress/expected/hash_part.out b/src/test/regress/expected/hash_part.out
index b79c2b44c1..ac3aabee02 100644
--- a/src/test/regress/expected/hash_part.out
+++ b/src/test/regress/expected/hash_part.out
@@ -19,10 +19,10 @@ SELECT satisfies_hash_partition('mchash1'::regclass, 4, 0, NULL);
 ERROR:  "mchash1" is not a hash partitioned table
 -- invalid modulus
 SELECT satisfies_hash_partition('mchash'::regclass, 0, 0, NULL);
-ERROR:  modulus for hash partition must be a positive integer
+ERROR:  modulus for hash partition must be an integer value greater than zero
 -- remainder too small
 SELECT satisfies_hash_partition('mchash'::regclass, 1, -1, NULL);
-ERROR:  remainder for hash partition must be a non-negative integer
+ERROR:  remainder for hash partition must be an integer value greater than or equal to zero
 -- remainder too large
 SELECT satisfies_hash_partition('mchash'::regclass, 1, 1, NULL);
 ERROR:  remainder for hash partition must be less than modulus
-- 
2.25.1

#17Fujii Masao
masao.fujii@oss.nttdata.com
In reply to: Bharath Rupireddy (#16)
Re: Inaccurate error message when set fdw batch_size to 0

On 2021/05/26 15:22, Bharath Rupireddy wrote:

On Thu, May 20, 2021 at 2:43 PM Bharath Rupireddy
<bharath.rupireddyforpostgres@gmail.com> wrote:

Thanks. That looks better. PSA v4 patch.

Attaching v5 patch rebased on latest master.

The patch could not be applied cleanly because of recent commit d854720df6.
Could you rebase the patch?

-                       /* these must have a non-negative numeric value */
+                       /* these must have a positive numeric value */

Isn't it better to replace this with "these must have a floating point value
greater than or equal to zero"?

-                                                errmsg("%s requires a non-negative numeric value",
+                                                errmsg("\"%s\" must be a numeric value greater than or equal to zero",

"numeric" should be "floating point"?

+    <quote>foo must be a numeric value greater than zero</quote> or
+    <quote>foo must be a numeric value greater than or equal to zero</quote>
+    if option <quote>foo</quote> expects a numeric value

Maybe this description about numeric value is redundant
because there is already the description about integer value?

- /* Number of workers should be non-negative. */

Isn't it better to replace this with "Number of workers should be greater than zero"
rather than removing the comment?

Regards,

--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION

#18Bharath Rupireddy
bharath.rupireddyforpostgres@gmail.com
In reply to: Fujii Masao (#17)
1 attachment(s)
Re: Inaccurate error message when set fdw batch_size to 0

On Fri, Jul 9, 2021 at 6:25 AM Fujii Masao <masao.fujii@oss.nttdata.com> wrote:

The patch could not be applied cleanly because of recent commit d854720df6.
Could you rebase the patch?

Thanks. Done.

-                       /* these must have a non-negative numeric value */
+                       /* these must have a positive numeric value */

Isn't it better to replace this with "these must have a floating point value
greater than or equal to zero"?

Changed.

-                                                errmsg("%s requires a non-negative numeric value",
+                                                errmsg("\"%s\" must be a numeric value greater than or equal to zero",

"numeric" should be "floating point"?

Changed.

+    <quote>foo must be a numeric value greater than zero</quote> or
+    <quote>foo must be a numeric value greater than or equal to zero</quote>
+    if option <quote>foo</quote> expects a numeric value

Maybe this description about numeric value is redundant
because there is already the description about integer value?

Removed.

- /* Number of workers should be non-negative. */

Isn't it better to replace this with "Number of workers should be greater than zero"
rather than removing the comment?

Changed.

PSA v6 patch.

Regards,
Bharath Rupireddy.

Attachments:

v6-0001-Disambiguate-error-messages-that-use-non-negative.patchapplication/octet-stream; name=v6-0001-Disambiguate-error-messages-that-use-non-negative.patchDownload
From 0a97d861ad1f0b7112612fc6bcc9536477e4a236 Mon Sep 17 00:00:00 2001
From: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Date: Fri, 9 Jul 2021 02:40:31 +0000
Subject: [PATCH v6] Disambiguate error messages that use "non-negative"

Using "non-negative" word in the error message looks ambiguous
since value 0 can't be considered as either a positive or negative
integer and some users might think "positive" is the same as
"non-negative". So, be clear with the following messages:
if (foo <= 0) then use "foo must be greater than zero" and
if (foo < 0) then use "foo must be greater than or equal to zero"

Also, added a note in the Error Message Style Guide to help writing
the new messages.

Authors: Hou Zhijie, Bharath Rupireddy.
---
 contrib/postgres_fdw/option.c           |  9 ++++++---
 doc/src/sgml/sources.sgml               | 11 +++++++++++
 src/backend/access/transam/parallel.c   |  2 +-
 src/backend/partitioning/partbounds.c   |  4 ++--
 src/backend/utils/adt/tsquery_op.c      |  2 +-
 src/bin/scripts/vacuumdb.c              |  2 +-
 src/test/modules/test_shm_mq/test.c     | 10 +++++-----
 src/test/regress/expected/hash_part.out |  4 ++--
 8 files changed, 29 insertions(+), 15 deletions(-)

diff --git a/contrib/postgres_fdw/option.c b/contrib/postgres_fdw/option.c
index 4593cbc540..c574ca2cf3 100644
--- a/contrib/postgres_fdw/option.c
+++ b/contrib/postgres_fdw/option.c
@@ -119,7 +119,10 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
 		else if (strcmp(def->defname, "fdw_startup_cost") == 0 ||
 				 strcmp(def->defname, "fdw_tuple_cost") == 0)
 		{
-			/* these must have a non-negative numeric value */
+			/*
+			 * These must have a floating point value greater than or equal to
+			 * zero.
+			 */
 			char	   *value;
 			double		real_val;
 			bool		is_parsed;
@@ -136,7 +139,7 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
 			if (real_val < 0)
 				ereport(ERROR,
 						(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-						 errmsg("\"%s\" requires a non-negative floating point value",
+						 errmsg("\"%s\" must be a floating point value greater than or equal to zero",
 								def->defname)));
 		}
 		else if (strcmp(def->defname, "extensions") == 0)
@@ -163,7 +166,7 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
 			if (int_val <= 0)
 				ereport(ERROR,
 						(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-						 errmsg("\"%s\" requires a non-negative integer value",
+						 errmsg("\"%s\" must be an integer value greater than zero",
 								def->defname)));
 		}
 		else if (strcmp(def->defname, "password_required") == 0)
diff --git a/doc/src/sgml/sources.sgml b/doc/src/sgml/sources.sgml
index 3f2c40b750..52804b1ae8 100644
--- a/doc/src/sgml/sources.sgml
+++ b/doc/src/sgml/sources.sgml
@@ -880,6 +880,17 @@ BETTER: unrecognized node type: 42
    </para>
   </simplesect>
 
+  <simplesect>
+   <title>Avoid Using <quote>non-negative</quote> Word in Error Messages</title>
+
+   <para>
+    Do not use <quote>non-negative</quote> word in error messages as it looks
+    ambiguous. Instead, use <quote>foo must be an integer value greater than zero</quote>
+    or  <quote>foo must be an integer value greater than or equal to zero</quote>
+    if option <quote>foo</quote> expects an integer value.
+   </para>
+  </simplesect>
+
   </sect1>
 
   <sect1 id="source-conventions">
diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c
index 3550ef13ba..983ddb0da5 100644
--- a/src/backend/access/transam/parallel.c
+++ b/src/backend/access/transam/parallel.c
@@ -170,7 +170,7 @@ CreateParallelContext(const char *library_name, const char *function_name,
 	/* It is unsafe to create a parallel context if not in parallel mode. */
 	Assert(IsInParallelMode());
 
-	/* Number of workers should be non-negative. */
+	/* Number of parallel workers should be greater than zero. */
 	Assert(nworkers >= 0);
 
 	/* We might be running in a short-lived memory context. */
diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c
index 38baaefcda..e55942e9c8 100644
--- a/src/backend/partitioning/partbounds.c
+++ b/src/backend/partitioning/partbounds.c
@@ -4761,11 +4761,11 @@ satisfies_hash_partition(PG_FUNCTION_ARGS)
 	if (modulus <= 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("modulus for hash partition must be a positive integer")));
+				 errmsg("modulus for hash partition must be an integer value greater than zero")));
 	if (remainder < 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("remainder for hash partition must be a non-negative integer")));
+				 errmsg("remainder for hash partition must be an integer value greater than or equal to zero")));
 	if (remainder >= modulus)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
diff --git a/src/backend/utils/adt/tsquery_op.c b/src/backend/utils/adt/tsquery_op.c
index 0575b55272..8211e6c9bc 100644
--- a/src/backend/utils/adt/tsquery_op.c
+++ b/src/backend/utils/adt/tsquery_op.c
@@ -121,7 +121,7 @@ tsquery_phrase_distance(PG_FUNCTION_ARGS)
 	if (distance < 0 || distance > MAXENTRYPOS)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("distance in phrase operator should be non-negative and less than %d",
+				 errmsg("distance in phrase operator must be an integer value between zero and %d inclusive",
 						MAXENTRYPOS)));
 	if (a->size == 0)
 	{
diff --git a/src/bin/scripts/vacuumdb.c b/src/bin/scripts/vacuumdb.c
index 61974baa78..8fff1c7730 100644
--- a/src/bin/scripts/vacuumdb.c
+++ b/src/bin/scripts/vacuumdb.c
@@ -203,7 +203,7 @@ main(int argc, char *argv[])
 				vacopts.parallel_workers = atoi(optarg);
 				if (vacopts.parallel_workers < 0)
 				{
-					pg_log_error("parallel workers for vacuum must be greater than or equal to zero");
+					pg_log_error("parallel workers for vacuum must be an integer value greater than or equal to zero");
 					exit(1);
 				}
 				break;
diff --git a/src/test/modules/test_shm_mq/test.c b/src/test/modules/test_shm_mq/test.c
index e5e32abac2..8867ba4e6b 100644
--- a/src/test/modules/test_shm_mq/test.c
+++ b/src/test/modules/test_shm_mq/test.c
@@ -57,17 +57,17 @@ test_shm_mq(PG_FUNCTION_ARGS)
 	if (loop_count < 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("repeat count size must be a non-negative integer")));
+				 errmsg("repeat count size must be an integer value greater than or equal to zero")));
 
 	/*
 	 * Since this test sends data using the blocking interfaces, it cannot
 	 * send data to itself.  Therefore, a minimum of 1 worker is required. Of
 	 * course, a negative worker count is nonsensical.
 	 */
-	if (nworkers < 1)
+	if (nworkers <= 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("number of workers must be a positive integer")));
+				 errmsg("number of workers must be an integer value greater than zero")));
 
 	/* Set up dynamic shared memory segment and background workers. */
 	test_shm_mq_setup(queue_size, nworkers, &seg, &outqh, &inqh);
@@ -149,7 +149,7 @@ test_shm_mq_pipelined(PG_FUNCTION_ARGS)
 	if (loop_count < 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("repeat count size must be a non-negative integer")));
+				 errmsg("repeat count size must be greater than or equal to zero")));
 
 	/*
 	 * Using the nonblocking interfaces, we can even send data to ourselves,
@@ -158,7 +158,7 @@ test_shm_mq_pipelined(PG_FUNCTION_ARGS)
 	if (nworkers < 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("number of workers must be a non-negative integer")));
+				 errmsg("number of workers must be greater than or equal to zero")));
 
 	/* Set up dynamic shared memory segment and background workers. */
 	test_shm_mq_setup(queue_size, nworkers, &seg, &outqh, &inqh);
diff --git a/src/test/regress/expected/hash_part.out b/src/test/regress/expected/hash_part.out
index b79c2b44c1..ac3aabee02 100644
--- a/src/test/regress/expected/hash_part.out
+++ b/src/test/regress/expected/hash_part.out
@@ -19,10 +19,10 @@ SELECT satisfies_hash_partition('mchash1'::regclass, 4, 0, NULL);
 ERROR:  "mchash1" is not a hash partitioned table
 -- invalid modulus
 SELECT satisfies_hash_partition('mchash'::regclass, 0, 0, NULL);
-ERROR:  modulus for hash partition must be a positive integer
+ERROR:  modulus for hash partition must be an integer value greater than zero
 -- remainder too small
 SELECT satisfies_hash_partition('mchash'::regclass, 1, -1, NULL);
-ERROR:  remainder for hash partition must be a non-negative integer
+ERROR:  remainder for hash partition must be an integer value greater than or equal to zero
 -- remainder too large
 SELECT satisfies_hash_partition('mchash'::regclass, 1, 1, NULL);
 ERROR:  remainder for hash partition must be less than modulus
-- 
2.25.1

#19Fujii Masao
masao.fujii@oss.nttdata.com
In reply to: Bharath Rupireddy (#18)
Re: Inaccurate error message when set fdw batch_size to 0

On 2021/07/09 11:41, Bharath Rupireddy wrote:

PSA v6 patch.

Thanks for updating the patch!

+  <simplesect>
+   <title>Avoid Using <quote>non-negative</quote> Word in Error Messages</title>
+
+   <para>
+    Do not use <quote>non-negative</quote> word in error messages as it looks
+    ambiguous. Instead, use <quote>foo must be an integer value greater than zero</quote>
+    or  <quote>foo must be an integer value greater than or equal to zero</quote>
+    if option <quote>foo</quote> expects an integer value.
+   </para>
+  </simplesect>

It seems suitable to put this guide under "Tricky Words to Avoid"
rather than adding it as separate section. Thought?

-	if (nworkers < 1)
+	if (nworkers <= 0)
  		ereport(ERROR,
  				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("number of workers must be a positive integer")));
+				 errmsg("number of workers must be an integer value greater than zero")));

You replaced "positve" with "greater than zero". So the error message
style guide should mention not only "non-negative" but also "positive"
(probably also "negative") keyword?

If this is true, there are still many messages using "positive" or "negative"
keyword as follows. We should also fix them at all? Of course,
which would increase the change too big unnecessarily, I'm afraid, though..

src/backend/storage/ipc/signalfuncs.c: errmsg("\"timeout\" must not be negative")));
src/backend/commands/functioncmds.c: errmsg("COST must be positive")));

Regards,

--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION

#20Bharath Rupireddy
bharath.rupireddyforpostgres@gmail.com
In reply to: Fujii Masao (#19)
Re: Inaccurate error message when set fdw batch_size to 0

On Mon, Jul 12, 2021 at 9:20 PM Fujii Masao <masao.fujii@oss.nttdata.com> wrote:

+  <simplesect>
+   <title>Avoid Using <quote>non-negative</quote> Word in Error Messages</title>
+
+   <para>
+    Do not use <quote>non-negative</quote> word in error messages as it looks
+    ambiguous. Instead, use <quote>foo must be an integer value greater than zero</quote>
+    or  <quote>foo must be an integer value greater than or equal to zero</quote>
+    if option <quote>foo</quote> expects an integer value.
+   </para>
+  </simplesect>

It seems suitable to put this guide under "Tricky Words to Avoid"
rather than adding it as separate section. Thought?

+1. I will change.

-       if (nworkers < 1)
+       if (nworkers <= 0)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-                                errmsg("number of workers must be a positive integer")));
+                                errmsg("number of workers must be an integer value greater than zero")));

You replaced "positve" with "greater than zero". So the error message
style guide should mention not only "non-negative" but also "positive"
(probably also "negative") keyword?

The main focus of the patch is to replace the ambiguous "non-negative"
work in the error message. Let's keep it to that. However, I changed
below two messages too to keep them in sync with nearby messages.
Also, there seems to be an ambiguity in treating 0 as a positive or
negative integer, I thought it makes sense to replace them. But, if
others don't agree, I'm happy to revert.

- errmsg("modulus for hash partition must be a positive integer")));
+ errmsg("modulus for hash partition must be an integer value greater
than zero")));
- errmsg("number of workers must be a positive integer")));
+ errmsg("number of workers must be an integer value greater than zero")));

If this is true, there are still many messages using "positive" or "negative"
keyword as follows. We should also fix them at all? Of course,
which would increase the change too big unnecessarily, I'm afraid, though..

src/backend/storage/ipc/signalfuncs.c: errmsg("\"timeout\" must not be negative")));
src/backend/commands/functioncmds.c: errmsg("COST must be positive")));

You are right. The change is going to be an unnecessary one. So, let's
not do that.

Regards,
Bharath Rupireddy.

#21Bharath Rupireddy
bharath.rupireddyforpostgres@gmail.com
In reply to: Bharath Rupireddy (#20)
1 attachment(s)
Re: Inaccurate error message when set fdw batch_size to 0

On Mon, Jul 12, 2021 at 10:11 PM Bharath Rupireddy
<bharath.rupireddyforpostgres@gmail.com> wrote:

On Mon, Jul 12, 2021 at 9:20 PM Fujii Masao <masao.fujii@oss.nttdata.com> wrote:

+  <simplesect>
+   <title>Avoid Using <quote>non-negative</quote> Word in Error Messages</title>
+
+   <para>
+    Do not use <quote>non-negative</quote> word in error messages as it looks
+    ambiguous. Instead, use <quote>foo must be an integer value greater than zero</quote>
+    or  <quote>foo must be an integer value greater than or equal to zero</quote>
+    if option <quote>foo</quote> expects an integer value.
+   </para>
+  </simplesect>

It seems suitable to put this guide under "Tricky Words to Avoid"
rather than adding it as separate section. Thought?

+1. I will change.

PSA v7 patch with the above change.

Regards,
Bharath Rupireddy.

Attachments:

v7-0001-Disambiguate-error-messages-that-use-non-negative.patchapplication/octet-stream; name=v7-0001-Disambiguate-error-messages-that-use-non-negative.patchDownload
From f80c97e4cee15ce1ebc2e609bd053e04efed859d Mon Sep 17 00:00:00 2001
From: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Date: Thu, 15 Jul 2021 14:22:04 +0000
Subject: [PATCH v7] Disambiguate error messages that use "non-negative"

Using "non-negative" word in the error message looks ambiguous
since value 0 can't be considered as either a positive or negative
integer and some users might think "positive" is the same as
"non-negative". So, be clear with the following messages:
if (foo <= 0) then use "foo must be greater than zero" and
if (foo < 0) then use "foo must be greater than or equal to zero"

Also, added a note in the Error Message Style Guide to help writing
the new messages.

Authors: Hou Zhijie, Bharath Rupireddy.
---
 contrib/postgres_fdw/option.c           |  9 ++++++---
 doc/src/sgml/sources.sgml               | 10 ++++++++++
 src/backend/access/transam/parallel.c   |  2 +-
 src/backend/partitioning/partbounds.c   |  4 ++--
 src/backend/utils/adt/tsquery_op.c      |  2 +-
 src/bin/scripts/vacuumdb.c              |  2 +-
 src/test/modules/test_shm_mq/test.c     | 10 +++++-----
 src/test/regress/expected/hash_part.out |  4 ++--
 8 files changed, 28 insertions(+), 15 deletions(-)

diff --git a/contrib/postgres_fdw/option.c b/contrib/postgres_fdw/option.c
index 4593cbc540..c574ca2cf3 100644
--- a/contrib/postgres_fdw/option.c
+++ b/contrib/postgres_fdw/option.c
@@ -119,7 +119,10 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
 		else if (strcmp(def->defname, "fdw_startup_cost") == 0 ||
 				 strcmp(def->defname, "fdw_tuple_cost") == 0)
 		{
-			/* these must have a non-negative numeric value */
+			/*
+			 * These must have a floating point value greater than or equal to
+			 * zero.
+			 */
 			char	   *value;
 			double		real_val;
 			bool		is_parsed;
@@ -136,7 +139,7 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
 			if (real_val < 0)
 				ereport(ERROR,
 						(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-						 errmsg("\"%s\" requires a non-negative floating point value",
+						 errmsg("\"%s\" must be a floating point value greater than or equal to zero",
 								def->defname)));
 		}
 		else if (strcmp(def->defname, "extensions") == 0)
@@ -163,7 +166,7 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
 			if (int_val <= 0)
 				ereport(ERROR,
 						(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-						 errmsg("\"%s\" requires a non-negative integer value",
+						 errmsg("\"%s\" must be an integer value greater than zero",
 								def->defname)));
 		}
 		else if (strcmp(def->defname, "password_required") == 0)
diff --git a/doc/src/sgml/sources.sgml b/doc/src/sgml/sources.sgml
index 3f2c40b750..80ad73f8d0 100644
--- a/doc/src/sgml/sources.sgml
+++ b/doc/src/sgml/sources.sgml
@@ -828,6 +828,16 @@ BETTER: unrecognized node type: 42
    </para>
   </formalpara>
 
+  <formalpara>
+    <title>non-negative</title>
+   <para>
+    Do not use <quote>non-negative</quote> word in error messages as it looks
+    ambiguous. Instead, use <quote>foo must be an integer value greater than
+    zero</quote> or <quote>foo must be an integer value greater than or equal
+    to zero</quote> if option <quote>foo</quote> expects an integer value.
+   </para>
+  </formalpara>
+
   </simplesect>
 
   <simplesect>
diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c
index 3550ef13ba..983ddb0da5 100644
--- a/src/backend/access/transam/parallel.c
+++ b/src/backend/access/transam/parallel.c
@@ -170,7 +170,7 @@ CreateParallelContext(const char *library_name, const char *function_name,
 	/* It is unsafe to create a parallel context if not in parallel mode. */
 	Assert(IsInParallelMode());
 
-	/* Number of workers should be non-negative. */
+	/* Number of parallel workers should be greater than zero. */
 	Assert(nworkers >= 0);
 
 	/* We might be running in a short-lived memory context. */
diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c
index 1ec141b9eb..3aa6c12c09 100644
--- a/src/backend/partitioning/partbounds.c
+++ b/src/backend/partitioning/partbounds.c
@@ -4760,11 +4760,11 @@ satisfies_hash_partition(PG_FUNCTION_ARGS)
 	if (modulus <= 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("modulus for hash partition must be a positive integer")));
+				 errmsg("modulus for hash partition must be an integer value greater than zero")));
 	if (remainder < 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("remainder for hash partition must be a non-negative integer")));
+				 errmsg("remainder for hash partition must be an integer value greater than or equal to zero")));
 	if (remainder >= modulus)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
diff --git a/src/backend/utils/adt/tsquery_op.c b/src/backend/utils/adt/tsquery_op.c
index 0575b55272..8211e6c9bc 100644
--- a/src/backend/utils/adt/tsquery_op.c
+++ b/src/backend/utils/adt/tsquery_op.c
@@ -121,7 +121,7 @@ tsquery_phrase_distance(PG_FUNCTION_ARGS)
 	if (distance < 0 || distance > MAXENTRYPOS)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("distance in phrase operator should be non-negative and less than %d",
+				 errmsg("distance in phrase operator must be an integer value between zero and %d inclusive",
 						MAXENTRYPOS)));
 	if (a->size == 0)
 	{
diff --git a/src/bin/scripts/vacuumdb.c b/src/bin/scripts/vacuumdb.c
index 61974baa78..8fff1c7730 100644
--- a/src/bin/scripts/vacuumdb.c
+++ b/src/bin/scripts/vacuumdb.c
@@ -203,7 +203,7 @@ main(int argc, char *argv[])
 				vacopts.parallel_workers = atoi(optarg);
 				if (vacopts.parallel_workers < 0)
 				{
-					pg_log_error("parallel workers for vacuum must be greater than or equal to zero");
+					pg_log_error("parallel workers for vacuum must be an integer value greater than or equal to zero");
 					exit(1);
 				}
 				break;
diff --git a/src/test/modules/test_shm_mq/test.c b/src/test/modules/test_shm_mq/test.c
index e5e32abac2..8867ba4e6b 100644
--- a/src/test/modules/test_shm_mq/test.c
+++ b/src/test/modules/test_shm_mq/test.c
@@ -57,17 +57,17 @@ test_shm_mq(PG_FUNCTION_ARGS)
 	if (loop_count < 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("repeat count size must be a non-negative integer")));
+				 errmsg("repeat count size must be an integer value greater than or equal to zero")));
 
 	/*
 	 * Since this test sends data using the blocking interfaces, it cannot
 	 * send data to itself.  Therefore, a minimum of 1 worker is required. Of
 	 * course, a negative worker count is nonsensical.
 	 */
-	if (nworkers < 1)
+	if (nworkers <= 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("number of workers must be a positive integer")));
+				 errmsg("number of workers must be an integer value greater than zero")));
 
 	/* Set up dynamic shared memory segment and background workers. */
 	test_shm_mq_setup(queue_size, nworkers, &seg, &outqh, &inqh);
@@ -149,7 +149,7 @@ test_shm_mq_pipelined(PG_FUNCTION_ARGS)
 	if (loop_count < 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("repeat count size must be a non-negative integer")));
+				 errmsg("repeat count size must be greater than or equal to zero")));
 
 	/*
 	 * Using the nonblocking interfaces, we can even send data to ourselves,
@@ -158,7 +158,7 @@ test_shm_mq_pipelined(PG_FUNCTION_ARGS)
 	if (nworkers < 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("number of workers must be a non-negative integer")));
+				 errmsg("number of workers must be greater than or equal to zero")));
 
 	/* Set up dynamic shared memory segment and background workers. */
 	test_shm_mq_setup(queue_size, nworkers, &seg, &outqh, &inqh);
diff --git a/src/test/regress/expected/hash_part.out b/src/test/regress/expected/hash_part.out
index b79c2b44c1..ac3aabee02 100644
--- a/src/test/regress/expected/hash_part.out
+++ b/src/test/regress/expected/hash_part.out
@@ -19,10 +19,10 @@ SELECT satisfies_hash_partition('mchash1'::regclass, 4, 0, NULL);
 ERROR:  "mchash1" is not a hash partitioned table
 -- invalid modulus
 SELECT satisfies_hash_partition('mchash'::regclass, 0, 0, NULL);
-ERROR:  modulus for hash partition must be a positive integer
+ERROR:  modulus for hash partition must be an integer value greater than zero
 -- remainder too small
 SELECT satisfies_hash_partition('mchash'::regclass, 1, -1, NULL);
-ERROR:  remainder for hash partition must be a non-negative integer
+ERROR:  remainder for hash partition must be an integer value greater than or equal to zero
 -- remainder too large
 SELECT satisfies_hash_partition('mchash'::regclass, 1, 1, NULL);
 ERROR:  remainder for hash partition must be less than modulus
-- 
2.25.1

#22Bharath Rupireddy
bharath.rupireddyforpostgres@gmail.com
In reply to: Bharath Rupireddy (#21)
1 attachment(s)
Re: Inaccurate error message when set fdw batch_size to 0

On Thu, Jul 15, 2021 at 7:54 PM Bharath Rupireddy
<bharath.rupireddyforpostgres@gmail.com> wrote:

On Mon, Jul 12, 2021 at 10:11 PM Bharath Rupireddy
<bharath.rupireddyforpostgres@gmail.com> wrote:

On Mon, Jul 12, 2021 at 9:20 PM Fujii Masao <masao.fujii@oss.nttdata.com> wrote:

+  <simplesect>
+   <title>Avoid Using <quote>non-negative</quote> Word in Error Messages</title>
+
+   <para>
+    Do not use <quote>non-negative</quote> word in error messages as it looks
+    ambiguous. Instead, use <quote>foo must be an integer value greater than zero</quote>
+    or  <quote>foo must be an integer value greater than or equal to zero</quote>
+    if option <quote>foo</quote> expects an integer value.
+   </para>
+  </simplesect>

It seems suitable to put this guide under "Tricky Words to Avoid"
rather than adding it as separate section. Thought?

+1. I will change.

PSA v7 patch with the above change.

PSA v8 patch rebased on to latest master.

Regards,
Bharath Rupireddy.

Attachments:

v8-0001-Disambiguate-error-messages-that-use-non-negative.patchapplication/octet-stream; name=v8-0001-Disambiguate-error-messages-that-use-non-negative.patchDownload
From 21cd1f94fe0120c03c6bd7a4810e13b63c812f16 Mon Sep 17 00:00:00 2001
From: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Date: Mon, 26 Jul 2021 04:55:34 +0000
Subject: [PATCH v8] Disambiguate error messages that use "non-negative"

Using "non-negative" word in the error message looks ambiguous
since value 0 can't be considered as either a positive or negative
integer and some users might think "positive" is the same as
"non-negative". So, be clear with the following messages:
if (foo <= 0) then use "foo must be greater than zero" and
if (foo < 0) then use "foo must be greater than or equal to zero"

Also, added a note in the Error Message Style Guide to help writing
the new messages.
---
 contrib/postgres_fdw/option.c           |  9 ++++++---
 doc/src/sgml/sources.sgml               | 10 ++++++++++
 src/backend/access/transam/parallel.c   |  2 +-
 src/backend/partitioning/partbounds.c   |  4 ++--
 src/backend/utils/adt/tsquery_op.c      |  2 +-
 src/test/modules/test_shm_mq/test.c     | 10 +++++-----
 src/test/regress/expected/hash_part.out |  4 ++--
 7 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/contrib/postgres_fdw/option.c b/contrib/postgres_fdw/option.c
index 4593cbc540..c574ca2cf3 100644
--- a/contrib/postgres_fdw/option.c
+++ b/contrib/postgres_fdw/option.c
@@ -119,7 +119,10 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
 		else if (strcmp(def->defname, "fdw_startup_cost") == 0 ||
 				 strcmp(def->defname, "fdw_tuple_cost") == 0)
 		{
-			/* these must have a non-negative numeric value */
+			/*
+			 * These must have a floating point value greater than or equal to
+			 * zero.
+			 */
 			char	   *value;
 			double		real_val;
 			bool		is_parsed;
@@ -136,7 +139,7 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
 			if (real_val < 0)
 				ereport(ERROR,
 						(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-						 errmsg("\"%s\" requires a non-negative floating point value",
+						 errmsg("\"%s\" must be a floating point value greater than or equal to zero",
 								def->defname)));
 		}
 		else if (strcmp(def->defname, "extensions") == 0)
@@ -163,7 +166,7 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
 			if (int_val <= 0)
 				ereport(ERROR,
 						(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-						 errmsg("\"%s\" requires a non-negative integer value",
+						 errmsg("\"%s\" must be an integer value greater than zero",
 								def->defname)));
 		}
 		else if (strcmp(def->defname, "password_required") == 0)
diff --git a/doc/src/sgml/sources.sgml b/doc/src/sgml/sources.sgml
index 3f2c40b750..80ad73f8d0 100644
--- a/doc/src/sgml/sources.sgml
+++ b/doc/src/sgml/sources.sgml
@@ -828,6 +828,16 @@ BETTER: unrecognized node type: 42
    </para>
   </formalpara>
 
+  <formalpara>
+    <title>non-negative</title>
+   <para>
+    Do not use <quote>non-negative</quote> word in error messages as it looks
+    ambiguous. Instead, use <quote>foo must be an integer value greater than
+    zero</quote> or <quote>foo must be an integer value greater than or equal
+    to zero</quote> if option <quote>foo</quote> expects an integer value.
+   </para>
+  </formalpara>
+
   </simplesect>
 
   <simplesect>
diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c
index 3550ef13ba..983ddb0da5 100644
--- a/src/backend/access/transam/parallel.c
+++ b/src/backend/access/transam/parallel.c
@@ -170,7 +170,7 @@ CreateParallelContext(const char *library_name, const char *function_name,
 	/* It is unsafe to create a parallel context if not in parallel mode. */
 	Assert(IsInParallelMode());
 
-	/* Number of workers should be non-negative. */
+	/* Number of parallel workers should be greater than zero. */
 	Assert(nworkers >= 0);
 
 	/* We might be running in a short-lived memory context. */
diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c
index 12599da9a8..25018b1a8b 100644
--- a/src/backend/partitioning/partbounds.c
+++ b/src/backend/partitioning/partbounds.c
@@ -4760,11 +4760,11 @@ satisfies_hash_partition(PG_FUNCTION_ARGS)
 	if (modulus <= 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("modulus for hash partition must be a positive integer")));
+				 errmsg("modulus for hash partition must be an integer value greater than zero")));
 	if (remainder < 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("remainder for hash partition must be a non-negative integer")));
+				 errmsg("remainder for hash partition must be an integer value greater than or equal to zero")));
 	if (remainder >= modulus)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
diff --git a/src/backend/utils/adt/tsquery_op.c b/src/backend/utils/adt/tsquery_op.c
index 0575b55272..8211e6c9bc 100644
--- a/src/backend/utils/adt/tsquery_op.c
+++ b/src/backend/utils/adt/tsquery_op.c
@@ -121,7 +121,7 @@ tsquery_phrase_distance(PG_FUNCTION_ARGS)
 	if (distance < 0 || distance > MAXENTRYPOS)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("distance in phrase operator should be non-negative and less than %d",
+				 errmsg("distance in phrase operator must be an integer value between zero and %d inclusive",
 						MAXENTRYPOS)));
 	if (a->size == 0)
 	{
diff --git a/src/test/modules/test_shm_mq/test.c b/src/test/modules/test_shm_mq/test.c
index e5e32abac2..8867ba4e6b 100644
--- a/src/test/modules/test_shm_mq/test.c
+++ b/src/test/modules/test_shm_mq/test.c
@@ -57,17 +57,17 @@ test_shm_mq(PG_FUNCTION_ARGS)
 	if (loop_count < 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("repeat count size must be a non-negative integer")));
+				 errmsg("repeat count size must be an integer value greater than or equal to zero")));
 
 	/*
 	 * Since this test sends data using the blocking interfaces, it cannot
 	 * send data to itself.  Therefore, a minimum of 1 worker is required. Of
 	 * course, a negative worker count is nonsensical.
 	 */
-	if (nworkers < 1)
+	if (nworkers <= 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("number of workers must be a positive integer")));
+				 errmsg("number of workers must be an integer value greater than zero")));
 
 	/* Set up dynamic shared memory segment and background workers. */
 	test_shm_mq_setup(queue_size, nworkers, &seg, &outqh, &inqh);
@@ -149,7 +149,7 @@ test_shm_mq_pipelined(PG_FUNCTION_ARGS)
 	if (loop_count < 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("repeat count size must be a non-negative integer")));
+				 errmsg("repeat count size must be greater than or equal to zero")));
 
 	/*
 	 * Using the nonblocking interfaces, we can even send data to ourselves,
@@ -158,7 +158,7 @@ test_shm_mq_pipelined(PG_FUNCTION_ARGS)
 	if (nworkers < 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("number of workers must be a non-negative integer")));
+				 errmsg("number of workers must be greater than or equal to zero")));
 
 	/* Set up dynamic shared memory segment and background workers. */
 	test_shm_mq_setup(queue_size, nworkers, &seg, &outqh, &inqh);
diff --git a/src/test/regress/expected/hash_part.out b/src/test/regress/expected/hash_part.out
index b79c2b44c1..ac3aabee02 100644
--- a/src/test/regress/expected/hash_part.out
+++ b/src/test/regress/expected/hash_part.out
@@ -19,10 +19,10 @@ SELECT satisfies_hash_partition('mchash1'::regclass, 4, 0, NULL);
 ERROR:  "mchash1" is not a hash partitioned table
 -- invalid modulus
 SELECT satisfies_hash_partition('mchash'::regclass, 0, 0, NULL);
-ERROR:  modulus for hash partition must be a positive integer
+ERROR:  modulus for hash partition must be an integer value greater than zero
 -- remainder too small
 SELECT satisfies_hash_partition('mchash'::regclass, 1, -1, NULL);
-ERROR:  remainder for hash partition must be a non-negative integer
+ERROR:  remainder for hash partition must be an integer value greater than or equal to zero
 -- remainder too large
 SELECT satisfies_hash_partition('mchash'::regclass, 1, 1, NULL);
 ERROR:  remainder for hash partition must be less than modulus
-- 
2.25.1

#23Fujii Masao
masao.fujii@oss.nttdata.com
In reply to: Bharath Rupireddy (#22)
1 attachment(s)
Re: Inaccurate error message when set fdw batch_size to 0

On 2021/07/26 13:56, Bharath Rupireddy wrote:

On Thu, Jul 15, 2021 at 7:54 PM Bharath Rupireddy
<bharath.rupireddyforpostgres@gmail.com> wrote:

On Mon, Jul 12, 2021 at 10:11 PM Bharath Rupireddy
<bharath.rupireddyforpostgres@gmail.com> wrote:

On Mon, Jul 12, 2021 at 9:20 PM Fujii Masao <masao.fujii@oss.nttdata.com> wrote:

+  <simplesect>
+   <title>Avoid Using <quote>non-negative</quote> Word in Error Messages</title>
+
+   <para>
+    Do not use <quote>non-negative</quote> word in error messages as it looks
+    ambiguous. Instead, use <quote>foo must be an integer value greater than zero</quote>
+    or  <quote>foo must be an integer value greater than or equal to zero</quote>
+    if option <quote>foo</quote> expects an integer value.
+   </para>
+  </simplesect>

It seems suitable to put this guide under "Tricky Words to Avoid"
rather than adding it as separate section. Thought?

+1. I will change.

PSA v7 patch with the above change.

PSA v8 patch rebased on to latest master.

Thanks for updating the patch!

+  <formalpara>
+    <title>non-negative</title>
+   <para>
+    Do not use <quote>non-negative</quote> word in error messages as it looks
+    ambiguous. Instead, use <quote>foo must be an integer value greater than
+    zero</quote> or <quote>foo must be an integer value greater than or equal
+    to zero</quote> if option <quote>foo</quote> expects an integer value.
+   </para>
+  </formalpara>

This description looks a bit redundant. And IMO it's better to also document how "non-negative" is ambiguous. So what about the following description, instead? I replaced this description with the following. Patch attached. I also uppercased the first character "n" of "non-negative" at the title for the sake of consistency with other items.

+  <formalpara>
+    <title>Non-negative</title>
+   <para>
+    Avoid <quote>non-negative</quote> as it is ambiguous
+    about whether it accepts zero.  It's better to use
+    <quote>greater than zero</quote> or
+    <quote>greater than or equal to zero</quote>.
+   </para>
+  </formalpara>
-	/* Number of workers should be non-negative. */
+	/* Number of parallel workers should be greater than zero. */
  	Assert(nworkers >= 0);

This should be "greater than or equal to zero", instead? Anyway since this is comment not an error message, and also there are still other comments using "non-negative", I don't think we need to change only this comment for now. So I excluded this change from the patch. Maybe we can get rid of all "non-negative" from comments and documents later *if* necessary.

-				 errmsg("repeat count size must be a non-negative integer")));
+				 errmsg("repeat count size must be greater than or equal to zero")));
-				 errmsg("number of workers must be a non-negative integer")));
+				 errmsg("number of workers must be greater than or equal to zero")));

Isn't it better to replace "be greater" with "be an integer value greater"? I applied this to the patch.

Regards,

--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION

Attachments:

v8-0001-Disambiguate-error-messages-that-use-non-negative_fujii.patchtext/plain; charset=UTF-8; name=v8-0001-Disambiguate-error-messages-that-use-non-negative_fujii.patch; x-mac-creator=0; x-mac-type=0Download
diff --git a/contrib/postgres_fdw/option.c b/contrib/postgres_fdw/option.c
index 4593cbc540..c574ca2cf3 100644
--- a/contrib/postgres_fdw/option.c
+++ b/contrib/postgres_fdw/option.c
@@ -119,7 +119,10 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
 		else if (strcmp(def->defname, "fdw_startup_cost") == 0 ||
 				 strcmp(def->defname, "fdw_tuple_cost") == 0)
 		{
-			/* these must have a non-negative numeric value */
+			/*
+			 * These must have a floating point value greater than or equal to
+			 * zero.
+			 */
 			char	   *value;
 			double		real_val;
 			bool		is_parsed;
@@ -136,7 +139,7 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
 			if (real_val < 0)
 				ereport(ERROR,
 						(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-						 errmsg("\"%s\" requires a non-negative floating point value",
+						 errmsg("\"%s\" must be a floating point value greater than or equal to zero",
 								def->defname)));
 		}
 		else if (strcmp(def->defname, "extensions") == 0)
@@ -163,7 +166,7 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
 			if (int_val <= 0)
 				ereport(ERROR,
 						(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-						 errmsg("\"%s\" requires a non-negative integer value",
+						 errmsg("\"%s\" must be an integer value greater than zero",
 								def->defname)));
 		}
 		else if (strcmp(def->defname, "password_required") == 0)
diff --git a/doc/src/sgml/sources.sgml b/doc/src/sgml/sources.sgml
index 3f2c40b750..e6ae02f2af 100644
--- a/doc/src/sgml/sources.sgml
+++ b/doc/src/sgml/sources.sgml
@@ -828,6 +828,16 @@ BETTER: unrecognized node type: 42
    </para>
   </formalpara>
 
+  <formalpara>
+    <title>Non-negative</title>
+   <para>
+    Avoid <quote>non-negative</quote> as it is ambiguous
+    about whether it accepts zero.  It's better to use
+    <quote>greater than zero</quote> or
+    <quote>greater than or equal to zero</quote>.
+   </para>
+  </formalpara>
+
   </simplesect>
 
   <simplesect>
diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c
index 12599da9a8..25018b1a8b 100644
--- a/src/backend/partitioning/partbounds.c
+++ b/src/backend/partitioning/partbounds.c
@@ -4760,11 +4760,11 @@ satisfies_hash_partition(PG_FUNCTION_ARGS)
 	if (modulus <= 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("modulus for hash partition must be a positive integer")));
+				 errmsg("modulus for hash partition must be an integer value greater than zero")));
 	if (remainder < 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("remainder for hash partition must be a non-negative integer")));
+				 errmsg("remainder for hash partition must be an integer value greater than or equal to zero")));
 	if (remainder >= modulus)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
diff --git a/src/backend/utils/adt/tsquery_op.c b/src/backend/utils/adt/tsquery_op.c
index 0575b55272..8211e6c9bc 100644
--- a/src/backend/utils/adt/tsquery_op.c
+++ b/src/backend/utils/adt/tsquery_op.c
@@ -121,7 +121,7 @@ tsquery_phrase_distance(PG_FUNCTION_ARGS)
 	if (distance < 0 || distance > MAXENTRYPOS)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("distance in phrase operator should be non-negative and less than %d",
+				 errmsg("distance in phrase operator must be an integer value between zero and %d inclusive",
 						MAXENTRYPOS)));
 	if (a->size == 0)
 	{
diff --git a/src/test/modules/test_shm_mq/test.c b/src/test/modules/test_shm_mq/test.c
index e5e32abac2..2d8d695f97 100644
--- a/src/test/modules/test_shm_mq/test.c
+++ b/src/test/modules/test_shm_mq/test.c
@@ -57,17 +57,17 @@ test_shm_mq(PG_FUNCTION_ARGS)
 	if (loop_count < 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("repeat count size must be a non-negative integer")));
+				 errmsg("repeat count size must be an integer value greater than or equal to zero")));
 
 	/*
 	 * Since this test sends data using the blocking interfaces, it cannot
 	 * send data to itself.  Therefore, a minimum of 1 worker is required. Of
 	 * course, a negative worker count is nonsensical.
 	 */
-	if (nworkers < 1)
+	if (nworkers <= 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("number of workers must be a positive integer")));
+				 errmsg("number of workers must be an integer value greater than zero")));
 
 	/* Set up dynamic shared memory segment and background workers. */
 	test_shm_mq_setup(queue_size, nworkers, &seg, &outqh, &inqh);
@@ -149,7 +149,7 @@ test_shm_mq_pipelined(PG_FUNCTION_ARGS)
 	if (loop_count < 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("repeat count size must be a non-negative integer")));
+				 errmsg("repeat count size must be an integer value greater than or equal to zero")));
 
 	/*
 	 * Using the nonblocking interfaces, we can even send data to ourselves,
@@ -158,7 +158,7 @@ test_shm_mq_pipelined(PG_FUNCTION_ARGS)
 	if (nworkers < 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("number of workers must be a non-negative integer")));
+				 errmsg("number of workers must be an integer value greater than or equal to zero")));
 
 	/* Set up dynamic shared memory segment and background workers. */
 	test_shm_mq_setup(queue_size, nworkers, &seg, &outqh, &inqh);
diff --git a/src/test/regress/expected/hash_part.out b/src/test/regress/expected/hash_part.out
index b79c2b44c1..ac3aabee02 100644
--- a/src/test/regress/expected/hash_part.out
+++ b/src/test/regress/expected/hash_part.out
@@ -19,10 +19,10 @@ SELECT satisfies_hash_partition('mchash1'::regclass, 4, 0, NULL);
 ERROR:  "mchash1" is not a hash partitioned table
 -- invalid modulus
 SELECT satisfies_hash_partition('mchash'::regclass, 0, 0, NULL);
-ERROR:  modulus for hash partition must be a positive integer
+ERROR:  modulus for hash partition must be an integer value greater than zero
 -- remainder too small
 SELECT satisfies_hash_partition('mchash'::regclass, 1, -1, NULL);
-ERROR:  remainder for hash partition must be a non-negative integer
+ERROR:  remainder for hash partition must be an integer value greater than or equal to zero
 -- remainder too large
 SELECT satisfies_hash_partition('mchash'::regclass, 1, 1, NULL);
 ERROR:  remainder for hash partition must be less than modulus
#24Bharath Rupireddy
bharath.rupireddyforpostgres@gmail.com
In reply to: Fujii Masao (#23)
Re: Inaccurate error message when set fdw batch_size to 0

On Mon, Jul 26, 2021 at 9:37 PM Fujii Masao <masao.fujii@oss.nttdata.com> wrote:

+  <formalpara>
+    <title>non-negative</title>
+   <para>
+    Do not use <quote>non-negative</quote> word in error messages as it looks
+    ambiguous. Instead, use <quote>foo must be an integer value greater than
+    zero</quote> or <quote>foo must be an integer value greater than or equal
+    to zero</quote> if option <quote>foo</quote> expects an integer value.
+   </para>
+  </formalpara>

This description looks a bit redundant. And IMO it's better to also document how "non-negative" is ambiguous. So what about the following description, instead? I replaced this description with the following. Patch attached. I also uppercased the first character "n" of "non-negative" at the title for the sake of consistency with other items.

+  <formalpara>
+    <title>Non-negative</title>
+   <para>
+    Avoid <quote>non-negative</quote> as it is ambiguous
+    about whether it accepts zero.  It's better to use
+    <quote>greater than zero</quote> or
+    <quote>greater than or equal to zero</quote>.
+   </para>
+  </formalpara>

LGTM.

-       /* Number of workers should be non-negative. */
+       /* Number of parallel workers should be greater than zero. */
Assert(nworkers >= 0);

This should be "greater than or equal to zero", instead? Anyway since this is comment not an error message, and also there are still other comments using "non-negative", I don't think we need to change only this comment for now. So I excluded this change from the patch. Maybe we can get rid of all "non-negative" from comments and documents later *if* necessary.

+1 to not change any code comments.

-                                errmsg("repeat count size must be a non-negative integer")));
+                                errmsg("repeat count size must be greater than or equal to zero")));
-                                errmsg("number of workers must be a non-negative integer")));
+                                errmsg("number of workers must be greater than or equal to zero")));

Isn't it better to replace "be greater" with "be an integer value greater"? I applied this to the patch.

+1.

Thanks for the v8 patch, it LGTM.

Regards,
Bharath Rupireddy.

#25Fujii Masao
masao.fujii@oss.nttdata.com
In reply to: Bharath Rupireddy (#24)
Re: Inaccurate error message when set fdw batch_size to 0

On 2021/07/27 15:06, Bharath Rupireddy wrote:

Thanks for the v8 patch, it LGTM.

Pushed. Thanks!

Regards,

--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION