Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pQ1Gx-0001sX-Bq for pgsql-hackers@arkaria.postgresql.org; Thu, 09 Feb 2023 07:23:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pQ1Gu-0008OB-UR for pgsql-hackers@arkaria.postgresql.org; Thu, 09 Feb 2023 07:23:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pQ1Gu-0008O1-LI for pgsql-hackers@lists.postgresql.org; Thu, 09 Feb 2023 07:23:08 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pQ1Gs-0000SH-JK for pgsql-hackers@lists.postgresql.org; Thu, 09 Feb 2023 07:23:08 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 3197N4x13845901; Thu, 9 Feb 2023 02:23:04 -0500 From: Tom Lane To: Jim Jones cc: Peter Smith , pgsql-hackers@lists.postgresql.org Subject: Re: [PATCH] Add pretty-printed XML output option In-reply-to: <3a3d7963-7f30-9e0a-5e7c-11382fed425a@uni-muenster.de> References: <2f5df461-dad8-6d7d-4568-08e10608a69b@uni-muenster.de> <8453003d-e1b1-7306-5fc5-6d1503adac1b@uni-muenster.de> <4359b355-5054-9758-ebab-a2c17a9b115e@uni-muenster.de> <2677159.1675700584@sss.pgh.pa.us> <226a2228-934b-22b8-45cd-dd144a3c443d@uni-muenster.de> <3a3d7963-7f30-9e0a-5e7c-11382fed425a@uni-muenster.de> Comments: In-reply-to Jim Jones message dated "Thu, 09 Feb 2023 08:16:50 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <3845899.1675927384.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 09 Feb 2023 02:23:04 -0500 Message-ID: <3845900.1675927384@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Jim Jones writes: > I see your point. If I got it right, you're suggesting the following = > change in the PG_TRY(); > =C2=A0=C2=A0 PG_TRY(); > =C2=A0=C2=A0=C2=A0 { > =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 int nbytes; > =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 if(!doc) > =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 xml_ereport(xm= lerrcxt, ERROR, ERRCODE_INTERNAL_ERROR, > =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2= =A0 =C2=A0=C2=A0=C2=A0 "could not parse the given XML document"); > =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 xmlDocDumpFormatMemory(doc, &xmlb= uf, &nbytes, 1); > =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 if(!nbytes || xmlerrcxt->err_occu= rred) > =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 xml_ereport(xm= lerrcxt, ERROR, ERRCODE_INTERNAL_ERROR, > =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2= =A0 =C2=A0=C2=A0=C2=A0 "could not indent the given XML document"); > =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 initStringInfo(&buf); > =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 appendStringInfoString(&buf, (con= st char *)xmlbuf); > =C2=A0=C2=A0=C2=A0 } > .. which will catch the doc =3D=3D NULL before calling xmlDocDumpFormatM= emory. Um ... why are you using PG_TRY here at all? It seems like you have full control of the actually likely error cases. The only plausible error out of the StringInfo calls is OOM, and you probably don't want to trap that at all. regards, tom lane