Skip to content

Commit 18391a8

Browse files
committed
Tweak wording of syntax error messages about bad CONTINUE/EXIT statements.
Try to avoid any possible confusion about what these messages mean.
1 parent aad663a commit 18391a8

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

src/pl/plpgsql/src/pl_gram.y

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,11 +1676,11 @@ stmt_exit : exit_type opt_label opt_exitcond
16761676
if (label == NULL)
16771677
ereport(ERROR,
16781678
(errcode(ERRCODE_SYNTAX_ERROR),
1679-
errmsg("label \"%s\" does not exist",
1679+
errmsg("there is no label \"%s\" surrounding this statement",
16801680
$2),
16811681
parser_errposition(@2)));
16821682
/* CONTINUE only allows loop labels */
1683-
if (label->itemno != PLPGSQL_LABEL_LOOP && !$1)
1683+
if (label->itemno != PLPGSQL_LABEL_LOOP && !new->is_exit)
16841684
ereport(ERROR,
16851685
(errcode(ERRCODE_SYNTAX_ERROR),
16861686
errmsg("block label \"%s\" cannot be used in CONTINUE",
@@ -1697,9 +1697,9 @@ stmt_exit : exit_type opt_label opt_exitcond
16971697
if (plpgsql_ns_find_nearest_loop(plpgsql_ns_top()) == NULL)
16981698
ereport(ERROR,
16991699
(errcode(ERRCODE_SYNTAX_ERROR),
1700-
/* translator: %s is EXIT or CONTINUE */
1701-
errmsg("%s cannot be used outside a loop",
1702-
plpgsql_stmt_typename((PLpgSQL_stmt *) new)),
1700+
new->is_exit ?
1701+
errmsg("EXIT cannot be used outside a loop, unless it has a label") :
1702+
errmsg("CONTINUE cannot be used outside a loop"),
17031703
parser_errposition(@1)));
17041704
}
17051705

src/test/regress/expected/plpgsql.out

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2843,15 +2843,15 @@ $$ language plpgsql;
28432843
ERROR: CONTINUE cannot be used outside a loop
28442844
LINE 4: continue;
28452845
^
2846-
-- should fail: EXIT is only legal inside a loop
2846+
-- should fail: unlabeled EXIT is only legal inside a loop
28472847
create function exit_error1() returns void as $$
28482848
begin
28492849
begin
28502850
exit;
28512851
end;
28522852
end;
28532853
$$ language plpgsql;
2854-
ERROR: EXIT cannot be used outside a loop
2854+
ERROR: EXIT cannot be used outside a loop, unless it has a label
28552855
LINE 4: exit;
28562856
^
28572857
-- should fail: no such label
@@ -2864,7 +2864,7 @@ begin
28642864
end;
28652865
end;
28662866
$$ language plpgsql;
2867-
ERROR: label "no_such_label" does not exist
2867+
ERROR: there is no label "no_such_label" surrounding this statement
28682868
LINE 5: continue no_such_label;
28692869
^
28702870
-- should fail: no such label
@@ -2877,7 +2877,7 @@ begin
28772877
end;
28782878
end;
28792879
$$ language plpgsql;
2880-
ERROR: label "no_such_label" does not exist
2880+
ERROR: there is no label "no_such_label" surrounding this statement
28812881
LINE 5: exit no_such_label;
28822882
^
28832883
-- should fail: CONTINUE can't reference the label of a named block

src/test/regress/sql/plpgsql.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2373,7 +2373,7 @@ begin
23732373
end;
23742374
$$ language plpgsql;
23752375

2376-
-- should fail: EXIT is only legal inside a loop
2376+
-- should fail: unlabeled EXIT is only legal inside a loop
23772377
create function exit_error1() returns void as $$
23782378
begin
23792379
begin

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy