Re: pl/python tracebacks

From: James William Pye <lists(at)jwp(dot)name>
To: Jan Urbański <wulczer(at)wulczer(dot)org>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Robert Haas <robertmhaas(at)gmail(dot)com>, Postgres - Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pl/python tracebacks
Date: 2011-03-01 20:23:31
Message-ID: 1318C4F9-5F36-4D0D-8ABE-97AAB24ACE80@jwp.name
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mar 1, 2011, at 12:10 PM, Jan Urbański wrote:
> So you end up with a context message saying "PL/Python function %s" and
> a detail message with the saved detail (if it's present) *and* the
> traceback. The problem is that the name of the function is already in
> the traceback, so there's no need for the context *if* there's a
> traceback present.
>
> The problem I'm having is technical: since the callback is already set
> when the code reaches the traceback-printing stage, you can't really
> unset it. AFAICS the elog code calls *all* callbacks from
> error_context_stack. So I can't prevent the context message from
> appearing. If I make the traceback part of the context as well, it's
> just going to appear together with the message from the callback.

I remember going through a lot of pain getting this done "right"
in pg-python[pl/py].

SELECT it_blows_up();
ERROR: function's "main" raised a Python exception
CONTEXT: [exception from Python]
Traceback (most recent call last):
File "public.it_blows_up()", line 13, in main
three()
File "public.it_blows_up()", line 10, in three
return two()
File "public.it_blows_up()", line 7, in two
return one()
File "public.it_blows_up()", line 4, in one
raise OverflowError("there's water everywhere")
OverflowError: there's water everywhere

[public.it_blows_up()]

IIRC, I unconditionally print the "[public.it_blows_up()]" part iff it's
not an ERROR. If it is an ERROR, I let the traceback rendering part of the code
handle it on the PL's entry point exit. It was really tricky to do this because I
was rendering the traceback *after* the error_context_stack had been called.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2011-03-01 20:31:12 Re: wrapping up this CommitFest (was Re: knngist - 0.8)
Previous Message Joshua D. Drake 2011-03-01 20:22:08 Re: wrapping up this CommitFest (was Re: knngist - 0.8)