Skip to content

Commit 0e1275f

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 024515c commit 0e1275f

File tree

6 files changed

+26
-13
lines changed

6 files changed

+26
-13
lines changed

contrib/postgres_fdw/option.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
119119
else if (strcmp(def->defname, "fdw_startup_cost") == 0 ||
120120
strcmp(def->defname, "fdw_tuple_cost") == 0)
121121
{
122-
/* these must have a non-negative numeric value */
122+
/*
123+
* These must have a floating point value greater than or equal to
124+
* zero.
125+
*/
123126
char *value;
124127
double real_val;
125128
bool is_parsed;
@@ -136,7 +139,7 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
136139
if (real_val < 0)
137140
ereport(ERROR,
138141
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
139-
errmsg("\"%s\" requires a non-negative floating point value",
142+
errmsg("\"%s\" must be a floating point value greater than or equal to zero",
140143
def->defname)));
141144
}
142145
else if (strcmp(def->defname, "extensions") == 0)
@@ -163,7 +166,7 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
163166
if (int_val <= 0)
164167
ereport(ERROR,
165168
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
166-
errmsg("\"%s\" requires a non-negative integer value",
169+
errmsg("\"%s\" must be an integer value greater than zero",
167170
def->defname)));
168171
}
169172
else if (strcmp(def->defname, "password_required") == 0)

doc/src/sgml/sources.sgml

+10
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,16 @@ BETTER: unrecognized node type: 42
828828
</para>
829829
</formalpara>
830830

831+
<formalpara>
832+
<title>Non-negative</title>
833+
<para>
834+
Avoid <quote>non-negative</quote> as it is ambiguous
835+
about whether it accepts zero. It's better to use
836+
<quote>greater than zero</quote> or
837+
<quote>greater than or equal to zero</quote>.
838+
</para>
839+
</formalpara>
840+
831841
</simplesect>
832842

833843
<simplesect>

src/backend/partitioning/partbounds.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -4760,11 +4760,11 @@ satisfies_hash_partition(PG_FUNCTION_ARGS)
47604760
if (modulus <= 0)
47614761
ereport(ERROR,
47624762
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4763-
errmsg("modulus for hash partition must be a positive integer")));
4763+
errmsg("modulus for hash partition must be an integer value greater than zero")));
47644764
if (remainder < 0)
47654765
ereport(ERROR,
47664766
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4767-
errmsg("remainder for hash partition must be a non-negative integer")));
4767+
errmsg("remainder for hash partition must be an integer value greater than or equal to zero")));
47684768
if (remainder >= modulus)
47694769
ereport(ERROR,
47704770
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),

src/backend/utils/adt/tsquery_op.c

+1-1
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

+5-5
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

+2-2
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)