Re: Error message with plpgsql CONTINUE - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Error message with plpgsql CONTINUE
Date
Msg-id 24629.1440273200@sss.pgh.pa.us
Whole thread Raw
In response to Re: Error message with plpgsql CONTINUE  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Error message with plpgsql CONTINUE  (Jim Nasby <Jim.Nasby@BlueTreble.com>)
List 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



pgsql-hackers by date:

Previous
From: Tomas Vondra
Date:
Subject: Re: PATCH: numeric timestamp in log_line_prefix
Next
From: Fabien COELHO
Date:
Subject: Re: PATCH: numeric timestamp in log_line_prefix