Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tXP2N-006ARu-0I for pgsql-hackers@arkaria.postgresql.org; Mon, 13 Jan 2025 18:19:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tXP2L-00CH7m-Ls for pgsql-hackers@arkaria.postgresql.org; Mon, 13 Jan 2025 18:19:42 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tXP2L-00CH7e-8r for pgsql-hackers@lists.postgresql.org; Mon, 13 Jan 2025 18:19:41 +0000 Received: from fout-b6-smtp.messagingengine.com ([202.12.124.149]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tXP2J-000Di3-0R for pgsql-hackers@lists.postgresql.org; Mon, 13 Jan 2025 18:19:41 +0000 Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfout.stl.internal (Postfix) with ESMTP id 2D3751140130; Mon, 13 Jan 2025 13:19:37 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-11.internal (MEProxy); Mon, 13 Jan 2025 13:19:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:message-id:mime-version:reply-to:subject :subject:to:to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1736792377; x=1736878777; bh=tEyVfJkU08OZ15qa1O6kfxLN9Yy4 13vLa3drTYZVwkk=; b=UFpBGIr2Qt/qrJLpqI3E6mzWT6/fQCBDkHDe0+dikb2D i4xhtfPDNN/2qm2bv7oktl9IgyhSxhG4IAbkHnEwdTPxbTYJwZQ2iBMfO2m9D8Zh 1yeQAsaydd/RTQUAeCYQO6t1KVxGam5TxMBxd5SZIS6ksjZEWtmcx4EfJpeFLgAH kN41PyONnBIv6S5l28br0jTRJQl9kDGI/x2QWYXvR5YbthiNs0LhmRoG+JfUDugV FWXzV7HdhGJYdG3UTBa1+nTpgk4fRTitAcXvCjOEjK+YCNNYyS4doSzoY5uaSMXC IailaGHMRidAiDkLybDkynDVLn4VkKR1NvA4M1bUlQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrudehgedguddutdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpeffhffvvefukfggtggugfesmhekreertddtjeen ucfhrhhomheptehlvhgrrhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhh drnhhoqdhiphdrohhrgheqnecuggftrfgrthhtvghrnhepieffveduhffgiedujeeihedv ieeiiefhudevjeeiffekteegjeelleetledtjedtnecuffhomhgrihhnpegvnhhtvghrph hrihhsvggusgdrtghomhenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgr ihhlfhhrohhmpegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhgpdhnsggprh gtphhtthhopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopegrmhhithhlrghn ghhothgvtdelsehgmhgrihhlrdgtohhmpdhrtghpthhtohepphhgshhqlhdqhhgrtghkvg hrsheslhhishhtshdrphhoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 13 Jan 2025 13:19:36 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1736792374; bh=32VoWuSP+pxSk/6oeWViJfvXDQWoes4tkAyrCw81cxg=; h=Date:From:To:Cc:Subject:From; b=BPyKm4/XAMPtqTFF2Xmm4KVHHYNIUXGSDiVWNWBrM5Kwnut/bqFE9OnHtK8QS9PKk b52NTJEUJb8pXA/PgjINoflhO8+dmmiV6wsUyaa0Me/oKkUoST8L/R/6blcgSv4V8v KTAzW0OD3r4VqiwF3zM+3HatG4+AEQ4nI8GmbVWwKNKV5ffLr0moeEq/7eASccPVGW qHwYomLVtdJQDTNCPlRLCSyQqYrqCxciFXKBbvUBZc94azrR1gBxdhnTai5lekNgjZ oLRsLpaZmDN3Eba9wJsRzdixVYHz7Qc54dlmGvU7P5yuozyzdG/yI2Q+g7WWxPMoOP kJ3PyCTMdOoVQ== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id 0DFEA329; Mon, 13 Jan 2025 19:19:34 +0100 (CET) Date: Mon, 13 Jan 2025 19:19:34 +0100 From: Alvaro Herrera To: Pg Hackers Cc: Amit Langote Subject: SQLJSON: errmsg(" .. should ...") -> must Message-ID: <202501131819.26ors7oouafu@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="auxdmhgqzuzucbal" Content-Disposition: inline Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --auxdmhgqzuzucbal Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit Hi There's a few recent SQL/JSON error messages in which we say something "should" be something else. We avoid this, so I think we shouldn't use it here either. (There's also wparser_def.c which uses "should" in that way, and I think it's there just because it's a dark unvisited corner that's been wrong for awhile.) While at it, I wasn't sure about the following: errmsg("JSON path expression in JSON_QUERY must return single item without wrapper") It seems a strange phrasing: I read it as meaning that the code is expecting that the path expression returns a single item and no wrapper around it. But what it really means is that if the user specifies that no wrapping is required, then a single item must be returned (so the "without wrapper" applies to the JSON_QUERY, not to the single item). I find this confusing, so I'd change it like this: errmsg("JSON path expression in JSON_QUERY must return single item when no wrapper is requested") which I think is clearer. Patch attached, for branch master. This applies to 17 cleanly, so I lean towards backpatching it all there. (The wparser_def.c changes go much longer back, but I see little point in backpatching those any further.) -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/ "Postgres is bloatware by design: it was built to house PhD theses." (Joey Hellerstein, SIGMOD annual conference 2002) --auxdmhgqzuzucbal Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename="0001-error-messages-must-use-must-rather-than-should.patch" From ae8f41ec3955055832e250bcd1419a2adff4e582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Herrera?= Date: Mon, 13 Jan 2025 19:10:35 +0100 Subject: [PATCH] error messages must use 'must' rather than 'should' --- src/backend/tsearch/wparser_def.c | 8 ++++---- src/backend/utils/adt/jsonpath_exec.c | 12 ++++++------ src/test/regress/expected/sqljson_jsontable.out | 2 +- src/test/regress/expected/sqljson_queryfuncs.out | 8 ++++---- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/backend/tsearch/wparser_def.c b/src/backend/tsearch/wparser_def.c index f26923d044b..79bcd32a063 100644 --- a/src/backend/tsearch/wparser_def.c +++ b/src/backend/tsearch/wparser_def.c @@ -2671,19 +2671,19 @@ prsd_headline(PG_FUNCTION_ARGS) if (min_words >= max_words) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("MinWords should be less than MaxWords"))); + errmsg("%s must be less than %s", "MinWords", "MaxWords"))); if (min_words <= 0) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("MinWords should be positive"))); + errmsg("%s must be positive", "MinWords"))); if (shortword < 0) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("ShortWord should be >= 0"))); + errmsg("%s must be >= 0", "ShortWord"))); if (max_fragments < 0) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("MaxFragments should be >= 0"))); + errmsg("%s must be >= 0", "MaxFragments"))); } /* Locate words and phrases matching the query */ diff --git a/src/backend/utils/adt/jsonpath_exec.c b/src/backend/utils/adt/jsonpath_exec.c index f6dfcb11a62..960fdec3dba 100644 --- a/src/backend/utils/adt/jsonpath_exec.c +++ b/src/backend/utils/adt/jsonpath_exec.c @@ -3977,13 +3977,13 @@ JsonPathQuery(Datum jb, JsonPath *jp, JsonWrapper wrapper, bool *empty, if (column_name) ereport(ERROR, (errcode(ERRCODE_MORE_THAN_ONE_SQL_JSON_ITEM), - errmsg("JSON path expression for column \"%s\" should return single item without wrapper", + errmsg("JSON path expression for column \"%s\" must return single item when no wrapper is requested", column_name), errhint("Use the WITH WRAPPER clause to wrap SQL/JSON items into an array."))); else ereport(ERROR, (errcode(ERRCODE_MORE_THAN_ONE_SQL_JSON_ITEM), - errmsg("JSON path expression in JSON_QUERY should return single item without wrapper"), + errmsg("JSON path expression in JSON_QUERY must return single item when no wrapper is requested"), errhint("Use the WITH WRAPPER clause to wrap SQL/JSON items into an array."))); } @@ -4041,12 +4041,12 @@ JsonPathValue(Datum jb, JsonPath *jp, bool *empty, bool *error, List *vars, if (column_name) ereport(ERROR, (errcode(ERRCODE_MORE_THAN_ONE_SQL_JSON_ITEM), - errmsg("JSON path expression for column \"%s\" should return single scalar item", + errmsg("JSON path expression for column \"%s\" must return single scalar item", column_name))); else ereport(ERROR, (errcode(ERRCODE_MORE_THAN_ONE_SQL_JSON_ITEM), - errmsg("JSON path expression in JSON_VALUE should return single scalar item"))); + errmsg("JSON path expression in JSON_VALUE must return single scalar item"))); } res = JsonValueListHead(&found); @@ -4065,12 +4065,12 @@ JsonPathValue(Datum jb, JsonPath *jp, bool *empty, bool *error, List *vars, if (column_name) ereport(ERROR, (errcode(ERRCODE_SQL_JSON_SCALAR_REQUIRED), - errmsg("JSON path expression for column \"%s\" should return single scalar item", + errmsg("JSON path expression for column \"%s\" must return single scalar item", column_name))); else ereport(ERROR, (errcode(ERRCODE_SQL_JSON_SCALAR_REQUIRED), - errmsg("JSON path expression in JSON_VALUE should return single scalar item"))); + errmsg("JSON path expression in JSON_VALUE must return single scalar item"))); } if (res->type == jbvNull) diff --git a/src/test/regress/expected/sqljson_jsontable.out b/src/test/regress/expected/sqljson_jsontable.out index d62d32241d3..458c5aaa5b0 100644 --- a/src/test/regress/expected/sqljson_jsontable.out +++ b/src/test/regress/expected/sqljson_jsontable.out @@ -710,7 +710,7 @@ LINE 1: SELECT * FROM JSON_TABLE(jsonb '{"a": 123}', '$' || '.' || '... ^ -- JsonPathQuery() error message mentioning column name SELECT * FROM JSON_TABLE('{"a": [{"b": "1"}, {"b": "2"}]}', '$' COLUMNS (b json path '$.a[*].b' ERROR ON ERROR)); -ERROR: JSON path expression for column "b" should return single item without wrapper +ERROR: JSON path expression for column "b" must return single item when no wrapper is requested HINT: Use the WITH WRAPPER clause to wrap SQL/JSON items into an array. -- JSON_TABLE: nested paths -- Duplicate path names diff --git a/src/test/regress/expected/sqljson_queryfuncs.out b/src/test/regress/expected/sqljson_queryfuncs.out index 329ef674961..5a35aeb7bba 100644 --- a/src/test/regress/expected/sqljson_queryfuncs.out +++ b/src/test/regress/expected/sqljson_queryfuncs.out @@ -344,7 +344,7 @@ SELECT JSON_VALUE(jsonb '[]', '$'); (1 row) SELECT JSON_VALUE(jsonb '[]', '$' ERROR ON ERROR); -ERROR: JSON path expression in JSON_VALUE should return single scalar item +ERROR: JSON path expression in JSON_VALUE must return single scalar item SELECT JSON_VALUE(jsonb '{}', '$'); json_value ------------ @@ -352,7 +352,7 @@ SELECT JSON_VALUE(jsonb '{}', '$'); (1 row) SELECT JSON_VALUE(jsonb '{}', '$' ERROR ON ERROR); -ERROR: JSON path expression in JSON_VALUE should return single scalar item +ERROR: JSON path expression in JSON_VALUE must return single scalar item SELECT JSON_VALUE(jsonb '1', '$.a'); json_value ------------ @@ -408,7 +408,7 @@ SELECT JSON_VALUE(jsonb '1', 'lax $.a' DEFAULT '2' ON EMPTY DEFAULT '3' ON ERROR SELECT JSON_VALUE(jsonb '1', 'lax $.a' ERROR ON EMPTY DEFAULT '3' ON ERROR); ERROR: no SQL/JSON item found for specified path SELECT JSON_VALUE(jsonb '[1,2]', '$[*]' ERROR ON ERROR); -ERROR: JSON path expression in JSON_VALUE should return single scalar item +ERROR: JSON path expression in JSON_VALUE must return single scalar item SELECT JSON_VALUE(jsonb '[1,2]', '$[*]' DEFAULT '0' ON ERROR); json_value ------------ @@ -806,7 +806,7 @@ SELECT JSON_QUERY(jsonb '[]', '$[*]' ERROR ON ERROR); -- NULL ON EMPTY (1 row) SELECT JSON_QUERY(jsonb '[1,2]', '$[*]' ERROR ON ERROR); -ERROR: JSON path expression in JSON_QUERY should return single item without wrapper +ERROR: JSON path expression in JSON_QUERY must return single item when no wrapper is requested HINT: Use the WITH WRAPPER clause to wrap SQL/JSON items into an array. SELECT JSON_QUERY(jsonb '[1,2]', '$[*]' DEFAULT '"empty"' ON ERROR); json_query -- 2.39.5 --auxdmhgqzuzucbal--