Re: How to handle error message in PG_CATCH

Lists: pgsql-hackers
From: Zdenek Kotala <Zdenek(dot)Kotala(at)Sun(dot)COM>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: How to handle error message in PG_CATCH
Date: 2008-03-04 09:11:47
Message-ID: 47CD1253.3090508@sun.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

I'm working on implementing pg_check functions. Because I want to test
whole table I need catch a error and handle it myself. I use following
construct:

PG_TRY();
{
...
ereport(ERROR, (errmsg("Error test")));
...
}
PG_CATCH();
{
errcontext("Context error");
EmitErrorReport();
FlushErrorState();
}
PG_END_TRY();

At the end I got following message:

ERROR: Error test
CONTEXT: Context error
server sent data ("D" message) without prior row description ("T" message)

and also nothing appears in a log file. Similar concept is used in
autovacuum.c.

Any idea what is wrong?

Thanks for help Zdenek


From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Zdenek Kotala <Zdenek(dot)Kotala(at)Sun(dot)COM>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: How to handle error message in PG_CATCH
Date: 2008-03-04 16:36:54
Message-ID: 20080304163654.GJ4755@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Zdenek Kotala wrote:

> PG_TRY();
> {
> ...
> ereport(ERROR, (errmsg("Error test")));
> ...
> }
> PG_CATCH();
> {
> errcontext("Context error");
> EmitErrorReport();
> FlushErrorState();
> }
> PG_END_TRY();
>
> At the end I got following message:
>
> ERROR: Error test
> CONTEXT: Context error
> server sent data ("D" message) without prior row description ("T" message)

I don't see anything wrong with this code. Perhaps the problem is
somewhere else?

--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.


From: Zdenek Kotala <Zdenek(dot)Kotala(at)Sun(dot)COM>
To: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: How to handle error message in PG_CATCH
Date: 2008-03-04 16:54:52
Message-ID: 47CD7EDC.1070309@sun.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Alvaro Herrera napsal(a):
> Zdenek Kotala wrote:
>
>> PG_TRY();
>> {
>> ...
>> ereport(ERROR, (errmsg("Error test")));
>> ...
>> }
>> PG_CATCH();
>> {
>> errcontext("Context error");
>> EmitErrorReport();
>> FlushErrorState();
>> }
>> PG_END_TRY();
>>
>> At the end I got following message:
>>
>> ERROR: Error test
>> CONTEXT: Context error
>> server sent data ("D" message) without prior row description ("T" message)
>
> I don't see anything wrong with this code. Perhaps the problem is
> somewhere else?
>

There is whole test code. It is store procedure and there are nothing
special. The difference between this and autovacuum is that autovacuum
works without client side.

Datum
pg_check(PG_FUNCTION_ARGS)
{
PG_TRY();
{
ereport(ERROR, (errmsg("Error test")));
}
PG_CATCH();
{
errcontext("Context error");
EmitErrorReport();
FlushErrorState();
}
PG_END_TRY();
PG_RETURN_DATUM(0);
}

Zdenek


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Zdenek Kotala <Zdenek(dot)Kotala(at)Sun(dot)COM>
Cc: Alvaro Herrera <alvherre(at)commandprompt(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: How to handle error message in PG_CATCH
Date: 2008-03-04 17:29:33
Message-ID: 16410.1204651773@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Zdenek Kotala <Zdenek(dot)Kotala(at)Sun(dot)COM> writes:
> Alvaro Herrera napsal(a):
>> Zdenek Kotala wrote:
>>> At the end I got following message:
>>>
>>> ERROR: Error test
>>> CONTEXT: Context error
>>> server sent data ("D" message) without prior row description ("T" message)
>>
>> I don't see anything wrong with this code. Perhaps the problem is
>> somewhere else?

> There is whole test code. It is store procedure and there are nothing
> special. The difference between this and autovacuum is that autovacuum
> works without client side.

The problem with this is it's violating the wire protocol. Once you've
sent the client an ERROR message, it no longer expects to see any result
from the SELECT that called the function.

regards, tom lane


From: Zdenek Kotala <Zdenek(dot)Kotala(at)Sun(dot)COM>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Alvaro Herrera <alvherre(at)commandprompt(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: How to handle error message in PG_CATCH
Date: 2008-03-04 19:30:43
Message-ID: 47CDA363.2080007@sun.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane napsal(a):
> Zdenek Kotala <Zdenek(dot)Kotala(at)Sun(dot)COM> writes:
>> Alvaro Herrera napsal(a):
>>> Zdenek Kotala wrote:
>>>> At the end I got following message:
>>>>
>>>> ERROR: Error test
>>>> CONTEXT: Context error
>>>> server sent data ("D" message) without prior row description ("T" message)
>>> I don't see anything wrong with this code. Perhaps the problem is
>>> somewhere else?
>
>> There is whole test code. It is store procedure and there are nothing
>> special. The difference between this and autovacuum is that autovacuum
>> works without client side.
>
> The problem with this is it's violating the wire protocol. Once you've
> sent the client an ERROR message, it no longer expects to see any result
> from the SELECT that called the function.
>

Thanks for explanation. I added extra error message at the end of
function and it works now.

Thanks Zdenek