Re: Refactoring: Use soft error reporting for *_opt_error functions

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Amul Sul <sulamul(at)gmail(dot)com>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Refactoring: Use soft error reporting for *_opt_error functions
Date: 2025-09-03 06:47:17
Message-ID: aLfkdZ3rLPu1biaE@paquier.xyz
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Sep 02, 2025 at 02:41:23PM +0530, Amul Sul wrote:
> The updated version is attached. In addition to the *_opt_error()
> functions, it also renames pg_lsn_in_internal to pg_lsn_in_safe and
> incorporates soft error handling.

Looks globally sensible to me. I was wondering for a bit if the JSON
path parts should be fed pieces of the soft errors that could be
retrieved when the numeric value parsing fails, but that does not seem
worth the extra information.

-pg_lsn_in_internal(const char *str, bool *have_error)
+pg_lsn_in_safe(const char *str, Node *escontext)
[...]
+ ereturn(escontext, InvalidXLogRecPtr,
+ (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+ errmsg("invalid input syntax for type %s: \"%s\"",
+ "pg_lsn", str)));

The same error message is repeated twice. How about using some gotos
and one single ereport instead of two? The same can be said for
numeric_div_safe() and numeric_mod_safe(), for the division-by-0
messages.

@@ -5629,11 +5629,11 @@ timestamp_part_common(PG_FUNCTION_ARGS, bool retnumeric)
[...]
+ PG_RETURN_NUMERIC(numeric_add_safe(int64_to_numeric(date2j(tm->tm_year, tm->tm_mon, tm->tm_mday)),

This part with DTK_JULIAN is hard to parse. Not your responsibility
here as you just replace a function name, just a remark in passing.
--
Michael

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrey Borodin 2025-09-03 06:47:28 Re: VM corruption on standby
Previous Message Alexander Korotkov 2025-09-03 06:37:04 Re: VM corruption on standby