From a84f95ffddbf9bfcf20f7e3b463e10ba1ec0b9f5 Mon Sep 17 00:00:00 2001 From: Fujii Masao Date: Wed, 28 Jul 2021 01:25:53 +0900 Subject: [PATCH] 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 --- contrib/postgres_fdw/option.c | 13 ++++++++----- doc/src/sgml/sources.sgml | 10 ++++++++++ src/backend/utils/adt/tsquery_op.c | 2 +- src/test/modules/test_shm_mq/test.c | 10 +++++----- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/contrib/postgres_fdw/option.c b/contrib/postgres_fdw/option.c index 67e1c59951a..0d755c69b2d 100644 --- a/contrib/postgres_fdw/option.c +++ b/contrib/postgres_fdw/option.c @@ -116,15 +116,18 @@ 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. + */ double val; char *endp; val = strtod(defGetString(def), &endp); if (*endp || val < 0) ereport(ERROR, - (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("%s requires a non-negative numeric value", + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("\"%s\" must be a floating point value greater than or equal to zero", def->defname))); } else if (strcmp(def->defname, "extensions") == 0) @@ -139,8 +142,8 @@ postgres_fdw_validator(PG_FUNCTION_ARGS) fetch_size = strtol(defGetString(def), NULL, 10); if (fetch_size <= 0) ereport(ERROR, - (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("%s requires a non-negative integer value", + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("\"%s\" must be an integer value greater than zero", def->defname))); } } diff --git a/doc/src/sgml/sources.sgml b/doc/src/sgml/sources.sgml index a1a14a43a07..179f4a19c2c 100644 --- a/doc/src/sgml/sources.sgml +++ b/doc/src/sgml/sources.sgml @@ -806,6 +806,16 @@ BETTER: unrecognized node type: 42 + + Non-negative + + Avoid non-negative as it is ambiguous + about whether it accepts zero. It's better to use + greater than zero or + greater than or equal to zero. + + + diff --git a/src/backend/utils/adt/tsquery_op.c b/src/backend/utils/adt/tsquery_op.c index 755c3e9ee8e..f575afe299a 100644 --- a/src/backend/utils/adt/tsquery_op.c +++ b/src/backend/utils/adt/tsquery_op.c @@ -120,7 +120,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 7a6ad23f755..0a6290f9b45 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);