Skip to content

Commit 92913fc

Browse files
committed
Avoid using ambiguous word "non-negative" in error messages.
The error messages using the word "non-negative" are confusing because it's ambiguous about whether it accepts zero or not. This commit improves those error messages by replacing it with less ambiguous word like "greater than zero" or "greater than or equal to zero". Also this commit added the note about the word "non-negative" to the error message style guide, to help writing the new error messages. When postgres_fdw option fetch_size was set to zero, previously the error message "fetch_size requires a non-negative integer value" was reported. This error message was outright buggy. Therefore back-patch to all supported versions where such buggy error message could be thrown. Reported-by: Hou Zhijie Author: Bharath Rupireddy Reviewed-by: Kyotaro Horiguchi, Fujii Masao Discussion: https://postgr.es/m/OS0PR01MB5716415335A06B489F1B3A8194569@OS0PR01MB5716.jpnprd01.prod.outlook.com
1 parent d629fcf commit 92913fc

File tree

6 files changed

+28
-15
lines changed

6 files changed

+28
-15
lines changed

contrib/postgres_fdw/option.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,18 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
115115
else if (strcmp(def->defname, "fdw_startup_cost") == 0 ||
116116
strcmp(def->defname, "fdw_tuple_cost") == 0)
117117
{
118-
/* these must have a non-negative numeric value */
118+
/*
119+
* These must have a floating point value greater than or equal to
120+
* zero.
121+
*/
119122
double val;
120123
char *endp;
121124

122125
val = strtod(defGetString(def), &endp);
123126
if (*endp || val < 0)
124127
ereport(ERROR,
125-
(errcode(ERRCODE_SYNTAX_ERROR),
126-
errmsg("%s requires a non-negative numeric value",
128+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
129+
errmsg("\"%s\" must be a floating point value greater than or equal to zero",
127130
def->defname)));
128131
}
129132
else if (strcmp(def->defname, "extensions") == 0)
@@ -138,8 +141,8 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
138141
fetch_size = strtol(defGetString(def), NULL, 10);
139142
if (fetch_size <= 0)
140143
ereport(ERROR,
141-
(errcode(ERRCODE_SYNTAX_ERROR),
142-
errmsg("%s requires a non-negative integer value",
144+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
145+
errmsg("\"%s\" must be an integer value greater than zero",
143146
def->defname)));
144147
}
145148
else if (strcmp(def->defname, "password_required") == 0)

doc/src/sgml/sources.sgml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,16 @@ BETTER: unrecognized node type: 42
820820
</para>
821821
</formalpara>
822822

823+
<formalpara>
824+
<title>Non-negative</title>
825+
<para>
826+
Avoid <quote>non-negative</quote> as it is ambiguous
827+
about whether it accepts zero. It's better to use
828+
<quote>greater than zero</quote> or
829+
<quote>greater than or equal to zero</quote>.
830+
</para>
831+
</formalpara>
832+
823833
</simplesect>
824834

825835
<simplesect>

src/backend/partitioning/partbounds.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4637,11 +4637,11 @@ satisfies_hash_partition(PG_FUNCTION_ARGS)
46374637
if (modulus <= 0)
46384638
ereport(ERROR,
46394639
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4640-
errmsg("modulus for hash partition must be a positive integer")));
4640+
errmsg("modulus for hash partition must be an integer value greater than zero")));
46414641
if (remainder < 0)
46424642
ereport(ERROR,
46434643
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4644-
errmsg("remainder for hash partition must be a non-negative integer")));
4644+
errmsg("remainder for hash partition must be an integer value greater than or equal to zero")));
46454645
if (remainder >= modulus)
46464646
ereport(ERROR,
46474647
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),

src/backend/utils/adt/tsquery_op.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ tsquery_phrase_distance(PG_FUNCTION_ARGS)
121121
if (distance < 0 || distance > MAXENTRYPOS)
122122
ereport(ERROR,
123123
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
124-
errmsg("distance in phrase operator should be non-negative and less than %d",
124+
errmsg("distance in phrase operator must be an integer value between zero and %d inclusive",
125125
MAXENTRYPOS)));
126126
if (a->size == 0)
127127
{

src/test/modules/test_shm_mq/test.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,17 @@ test_shm_mq(PG_FUNCTION_ARGS)
5757
if (loop_count < 0)
5858
ereport(ERROR,
5959
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
60-
errmsg("repeat count size must be a non-negative integer")));
60+
errmsg("repeat count size must be an integer value greater than or equal to zero")));
6161

6262
/*
6363
* Since this test sends data using the blocking interfaces, it cannot
6464
* send data to itself. Therefore, a minimum of 1 worker is required. Of
6565
* course, a negative worker count is nonsensical.
6666
*/
67-
if (nworkers < 1)
67+
if (nworkers <= 0)
6868
ereport(ERROR,
6969
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
70-
errmsg("number of workers must be a positive integer")));
70+
errmsg("number of workers must be an integer value greater than zero")));
7171

7272
/* Set up dynamic shared memory segment and background workers. */
7373
test_shm_mq_setup(queue_size, nworkers, &seg, &outqh, &inqh);
@@ -149,7 +149,7 @@ test_shm_mq_pipelined(PG_FUNCTION_ARGS)
149149
if (loop_count < 0)
150150
ereport(ERROR,
151151
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
152-
errmsg("repeat count size must be a non-negative integer")));
152+
errmsg("repeat count size must be an integer value greater than or equal to zero")));
153153

154154
/*
155155
* Using the nonblocking interfaces, we can even send data to ourselves,
@@ -158,7 +158,7 @@ test_shm_mq_pipelined(PG_FUNCTION_ARGS)
158158
if (nworkers < 0)
159159
ereport(ERROR,
160160
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
161-
errmsg("number of workers must be a non-negative integer")));
161+
errmsg("number of workers must be an integer value greater than or equal to zero")));
162162

163163
/* Set up dynamic shared memory segment and background workers. */
164164
test_shm_mq_setup(queue_size, nworkers, &seg, &outqh, &inqh);

src/test/regress/expected/hash_part.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ SELECT satisfies_hash_partition('mchash1'::regclass, 4, 0, NULL);
1919
ERROR: "mchash1" is not a hash partitioned table
2020
-- invalid modulus
2121
SELECT satisfies_hash_partition('mchash'::regclass, 0, 0, NULL);
22-
ERROR: modulus for hash partition must be a positive integer
22+
ERROR: modulus for hash partition must be an integer value greater than zero
2323
-- remainder too small
2424
SELECT satisfies_hash_partition('mchash'::regclass, 1, -1, NULL);
25-
ERROR: remainder for hash partition must be a non-negative integer
25+
ERROR: remainder for hash partition must be an integer value greater than or equal to zero
2626
-- remainder too large
2727
SELECT satisfies_hash_partition('mchash'::regclass, 1, 1, NULL);
2828
ERROR: remainder for hash partition must be less than modulus

0 commit comments

Comments
 (0)