Re: Propagate XLogFindNextRecord error to callers - Mailing list pgsql-hackers

From Chao Li
Subject Re: Propagate XLogFindNextRecord error to callers
Date
Msg-id 1D505B52-9D58-4783-846D-600391C2A3B1@gmail.com
Whole thread Raw
In response to Re: Propagate XLogFindNextRecord error to callers  (Anthonin Bonnefoy <anthonin.bonnefoy@datadoghq.com>)
Responses Re: Propagate XLogFindNextRecord error to callers
List pgsql-hackers

> On Feb 12, 2026, at 15:43, Anthonin Bonnefoy <anthonin.bonnefoy@datadoghq.com> wrote:
>
> On Wed, Feb 11, 2026 at 1:16 PM Mircea Cadariu <cadariu.mircea@gmail.com> wrote:
>> Indeed. Should we place this initialisation at the top of
>> XLogFindNextRecord, before any processing? At that point, there's
>> nothing to erase.
>
> That makes sense, I've added the '*errormsg = NULL' at the top of the function.
>
>> You can consider capitalising.
>
> Done
> <v5-0001-Propagate-errormsg-to-XLogFindNextRecord-caller.patch>

Hi Anthonin,

Thanks for the patch. I agree it’s useful to print a more detailed error message instead of the generic one.

From a design perspective, I’m not sure we need to add a new errormsg parameter to XLogFindNextRecord(). The new
parameterultimately just exposes state->errormsg_buf, so the returned errormsg implicitly depends on the lifetime of
state,and we also need extra handling for cases like errormsg == NULL. 

Instead, perhaps we could add a helper function, say XLogReaderGetLastError(XLogReaderState *state). which internally
pstrdup()sstate->errormsg_buf (after checking errormsg_deferred, etc.). That way the caller owns the returned string
explicitly,and there’s no hidden dependency on the reader state’s lifetime. 

This would also avoid changing the XLogFindNextRecord() signature while making the ownership semantics clearer.

What do you think?

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/







pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: DOCS - pg_waldump synopsis sgml markup
Next
From: Michael Paquier
Date:
Subject: Re: Re: A out of date comment of WaitForWALToBecomeAvailable