Re: Error message with plpgsql CONTINUE

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Error message with plpgsql CONTINUE
Date: 2015-08-22 19:53:20
Message-ID: 24629.1440273200@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I had a few second thoughts about the wording of the error messages
in this area.

First, consider

create or replace function foo() returns void language plpgsql as $$
begin
<<lab1>>
loop
exit lab1; -- ok
end loop;
loop
exit lab1; -- not so ok
end loop;
end$$;

ERROR: label "lab1" does not exist
LINE 8: exit lab1; -- not so ok
^

This message seems confusing: label "lab1" does exist, it's just not
attached to the right loop. In a larger function that might not be too
obvious, and I can easily imagine somebody wasting some time before
figuring out the cause of his problem. Given the way the namespace data
structure works, I am not sure that we can realistically detect at line 8
that there was an instance of lab1 earlier, but perhaps we could word the
error message to cover either possibility. Maybe something like "there is
no label "foo" surrounding this statement"?

Second, consider

create or replace function foo() returns void language plpgsql as $$
begin
<<lab1>>
begin
exit lab1; -- ok
exit; -- not so ok
end;
end$$;

ERROR: EXIT cannot be used outside a loop
LINE 6: exit; -- not so ok
^

This is not too accurate, as shown by the fact that the first EXIT is
accepted. Perhaps "EXIT without a label cannot be used outside a loop"?

I realize that this is pretty nitpicky, but if we're going to all the
trouble of improving the error messages about these things, seems like
we ought to be careful about what the messages actually say.

I'm not married to these particular wordings though. Suggestions?

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Fabien COELHO 2015-08-22 19:54:40 Re: PATCH: numeric timestamp in log_line_prefix
Previous Message Tomas Vondra 2015-08-22 18:39:58 Re: PATCH: numeric timestamp in log_line_prefix