Skip to content

Commit d852863

Browse files
committed
Error message editing in backend/catalog.
1 parent da4ed8b commit d852863

24 files changed

+600
-379
lines changed

src/backend/catalog/aclchk.c

Lines changed: 111 additions & 51 deletions
Large diffs are not rendered by default.

src/backend/catalog/dependency.c

Lines changed: 73 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/dependency.c,v 1.26 2003/06/29 00:33:42 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/dependency.c,v 1.27 2003/07/21 01:59:07 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -168,9 +168,11 @@ performDeletion(const ObjectAddress *object,
168168

169169
if (!recursiveDeletion(object, behavior, NOTICE,
170170
NULL, &oktodelete, depRel))
171-
elog(ERROR, "Cannot drop %s because other objects depend on it"
172-
"\n\tUse DROP ... CASCADE to drop the dependent objects too",
173-
objDescription);
171+
ereport(ERROR,
172+
(errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
173+
errmsg("cannot drop %s because other objects depend on it",
174+
objDescription),
175+
errhint("Use DROP ... CASCADE to drop the dependent objects too.")));
174176

175177
term_object_addresses(&oktodelete);
176178

@@ -226,8 +228,10 @@ deleteWhatDependsOn(const ObjectAddress *object,
226228
DROP_CASCADE,
227229
showNotices ? NOTICE : DEBUG2,
228230
&oktodelete, depRel))
229-
elog(ERROR, "Failed to drop all objects depending on %s",
230-
objDescription);
231+
ereport(ERROR,
232+
(errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
233+
errmsg("failed to drop all objects depending on %s",
234+
objDescription)));
231235

232236
/*
233237
* We do not need CommandCounterIncrement here, since if step 2 did
@@ -316,15 +320,17 @@ findAutoDeletableObjects(const ObjectAddress *object,
316320
break;
317321
case DEPENDENCY_PIN:
318322
/*
319-
* For a PIN dependency we just elog immediately; there
323+
* For a PIN dependency we just ereport immediately; there
320324
* won't be any others to examine, and we aren't ever
321325
* going to let the user delete it.
322326
*/
323-
elog(ERROR, "Cannot drop %s because it is required by the database system",
324-
getObjectDescription(object));
327+
ereport(ERROR,
328+
(errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
329+
errmsg("cannot drop %s because it is required by the database system",
330+
getObjectDescription(object))));
325331
break;
326332
default:
327-
elog(ERROR, "findAutoDeletableObjects: unknown dependency type '%c' for %s",
333+
elog(ERROR, "unrecognized dependency type '%c' for %s",
328334
foundDep->deptype, getObjectDescription(object));
329335
break;
330336
}
@@ -349,7 +355,7 @@ findAutoDeletableObjects(const ObjectAddress *object,
349355
* depRel is the already-open pg_depend relation.
350356
*
351357
*
352-
* In RESTRICT mode, we perform all the deletions anyway, but elog a message
358+
* In RESTRICT mode, we perform all the deletions anyway, but ereport a message
353359
* and return FALSE if we find a restriction violation. performDeletion
354360
* will then abort the transaction to nullify the deletions. We have to
355361
* do it this way to (a) report all the direct and indirect dependencies
@@ -447,16 +453,19 @@ recursiveDeletion(const ObjectAddress *object,
447453
* another object. We have three cases:
448454
*
449455
* 1. At the outermost recursion level, disallow the DROP.
450-
* (We just elog here, rather than proceeding, since no
456+
* (We just ereport here, rather than proceeding, since no
451457
* other dependencies are likely to be interesting.)
452458
*/
453459
if (callingObject == NULL)
454460
{
455461
char *otherObjDesc = getObjectDescription(&otherObject);
456462

457-
elog(ERROR, "Cannot drop %s because %s requires it"
458-
"\n\tYou may drop %s instead",
459-
objDescription, otherObjDesc, otherObjDesc);
463+
ereport(ERROR,
464+
(errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
465+
errmsg("cannot drop %s because %s requires it",
466+
objDescription, otherObjDesc),
467+
errhint("You may drop %s instead.",
468+
otherObjDesc)));
460469
}
461470

462471
/*
@@ -480,7 +489,7 @@ recursiveDeletion(const ObjectAddress *object,
480489
* owning object to recurse back to me.
481490
*/
482491
if (amOwned) /* shouldn't happen */
483-
elog(ERROR, "recursiveDeletion: multiple INTERNAL dependencies for %s",
492+
elog(ERROR, "multiple INTERNAL dependencies for %s",
484493
objDescription);
485494
owningObject = otherObject;
486495
amOwned = true;
@@ -492,11 +501,11 @@ recursiveDeletion(const ObjectAddress *object,
492501
* Should not happen; PIN dependencies should have zeroes
493502
* in the depender fields...
494503
*/
495-
elog(ERROR, "recursiveDeletion: incorrect use of PIN dependency with %s",
504+
elog(ERROR, "incorrect use of PIN dependency with %s",
496505
objDescription);
497506
break;
498507
default:
499-
elog(ERROR, "recursiveDeletion: unknown dependency type '%c' for %s",
508+
elog(ERROR, "unrecognized dependency type '%c' for %s",
500509
foundDep->deptype, objDescription);
501510
break;
502511
}
@@ -522,18 +531,21 @@ recursiveDeletion(const ObjectAddress *object,
522531
if (amOwned)
523532
{
524533
if (object_address_present(&owningObject, oktodelete))
525-
elog(DEBUG2, "Drop auto-cascades to %s",
526-
getObjectDescription(&owningObject));
534+
ereport(DEBUG2,
535+
(errmsg("drop auto-cascades to %s",
536+
getObjectDescription(&owningObject))));
527537
else if (behavior == DROP_RESTRICT)
528538
{
529-
elog(msglevel, "%s depends on %s",
530-
getObjectDescription(&owningObject),
531-
objDescription);
539+
ereport(msglevel,
540+
(errmsg("%s depends on %s",
541+
getObjectDescription(&owningObject),
542+
objDescription)));
532543
ok = false;
533544
}
534545
else
535-
elog(msglevel, "Drop cascades to %s",
536-
getObjectDescription(&owningObject));
546+
ereport(msglevel,
547+
(errmsg("drop cascades to %s",
548+
getObjectDescription(&owningObject))));
537549

538550
if (!recursiveDeletion(&owningObject, behavior, msglevel,
539551
object, oktodelete, depRel))
@@ -669,18 +681,21 @@ deleteDependentObjects(const ObjectAddress *object,
669681
* In that case, act like this link is AUTO, too.
670682
*/
671683
if (object_address_present(&otherObject, oktodelete))
672-
elog(DEBUG2, "Drop auto-cascades to %s",
673-
getObjectDescription(&otherObject));
684+
ereport(DEBUG2,
685+
(errmsg("drop auto-cascades to %s",
686+
getObjectDescription(&otherObject))));
674687
else if (behavior == DROP_RESTRICT)
675688
{
676-
elog(msglevel, "%s depends on %s",
677-
getObjectDescription(&otherObject),
678-
objDescription);
689+
ereport(msglevel,
690+
(errmsg("%s depends on %s",
691+
getObjectDescription(&otherObject),
692+
objDescription)));
679693
ok = false;
680694
}
681695
else
682-
elog(msglevel, "Drop cascades to %s",
683-
getObjectDescription(&otherObject));
696+
ereport(msglevel,
697+
(errmsg("drop cascades to %s",
698+
getObjectDescription(&otherObject))));
684699

685700
if (!recursiveDeletion(&otherObject, behavior, msglevel,
686701
object, oktodelete, depRel))
@@ -694,8 +709,9 @@ deleteDependentObjects(const ObjectAddress *object,
694709
* RESTRICT case. (However, normal dependencies on the
695710
* component object could still cause failure.)
696711
*/
697-
elog(DEBUG2, "Drop auto-cascades to %s",
698-
getObjectDescription(&otherObject));
712+
ereport(DEBUG2,
713+
(errmsg("drop auto-cascades to %s",
714+
getObjectDescription(&otherObject))));
699715

700716
if (!recursiveDeletion(&otherObject, behavior, msglevel,
701717
object, oktodelete, depRel))
@@ -704,14 +720,16 @@ deleteDependentObjects(const ObjectAddress *object,
704720
case DEPENDENCY_PIN:
705721

706722
/*
707-
* For a PIN dependency we just elog immediately; there
723+
* For a PIN dependency we just ereport immediately; there
708724
* won't be any others to report.
709725
*/
710-
elog(ERROR, "Cannot drop %s because it is required by the database system",
711-
objDescription);
726+
ereport(ERROR,
727+
(errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
728+
errmsg("cannot drop %s because it is required by the database system",
729+
objDescription)));
712730
break;
713731
default:
714-
elog(ERROR, "recursiveDeletion: unknown dependency type '%c' for %s",
732+
elog(ERROR, "unrecognized dependency type '%c' for %s",
715733
foundDep->deptype, objDescription);
716734
break;
717735
}
@@ -800,7 +818,7 @@ doDeletion(const ObjectAddress *object)
800818
break;
801819

802820
default:
803-
elog(ERROR, "doDeletion: Unsupported object class %u",
821+
elog(ERROR, "unrecognized object class: %u",
804822
object->classId);
805823
}
806824
}
@@ -968,12 +986,10 @@ find_expr_references_walker(Node *node,
968986
rtables = lnext(rtables);
969987
}
970988
if (rtables == NIL)
971-
elog(ERROR, "find_expr_references_walker: bogus varlevelsup %d",
972-
var->varlevelsup);
989+
elog(ERROR, "invalid varlevelsup %d", var->varlevelsup);
973990
rtable = lfirst(rtables);
974991
if (var->varno <= 0 || var->varno > length(rtable))
975-
elog(ERROR, "find_expr_references_walker: bogus varno %d",
976-
var->varno);
992+
elog(ERROR, "invalid varno %d", var->varno);
977993
rte = rt_fetch(var->varno, rtable);
978994
if (rte->rtekind == RTE_RELATION)
979995
{
@@ -992,8 +1008,7 @@ find_expr_references_walker(Node *node,
9921008
context->rtables = rtables;
9931009
if (var->varattno <= 0 ||
9941010
var->varattno > length(rte->joinaliasvars))
995-
elog(ERROR, "find_expr_references_walker: bogus varattno %d",
996-
var->varattno);
1011+
elog(ERROR, "invalid varattno %d", var->varattno);
9971012
find_expr_references_walker((Node *) nth(var->varattno - 1,
9981013
rte->joinaliasvars),
9991014
context);
@@ -1064,7 +1079,7 @@ find_expr_references_walker(Node *node,
10641079
if (is_subplan(node))
10651080
{
10661081
/* Extra work needed here if we ever need this case */
1067-
elog(ERROR, "find_expr_references_walker: already-planned subqueries not supported");
1082+
elog(ERROR, "already-planned subqueries not supported");
10681083
}
10691084
if (IsA(node, Query))
10701085
{
@@ -1400,8 +1415,7 @@ getObjectClass(const ObjectAddress *object)
14001415
return OCLASS_SCHEMA;
14011416
}
14021417

1403-
elog(ERROR, "getObjectClass: Unknown object class %u",
1404-
object->classId);
1418+
elog(ERROR, "unrecognized object class: %u", object->classId);
14051419
return OCLASS_CLASS; /* keep compiler quiet */
14061420
}
14071421

@@ -1457,7 +1471,7 @@ getObjectDescription(const ObjectAddress *object)
14571471
tup = systable_getnext(rcscan);
14581472

14591473
if (!HeapTupleIsValid(tup))
1460-
elog(ERROR, "getObjectDescription: Cast %u does not exist",
1474+
elog(ERROR, "could not find tuple for cast %u",
14611475
object->objectId);
14621476

14631477
castForm = (Form_pg_cast) GETSTRUCT(tup);
@@ -1491,7 +1505,7 @@ getObjectDescription(const ObjectAddress *object)
14911505
tup = systable_getnext(rcscan);
14921506

14931507
if (!HeapTupleIsValid(tup))
1494-
elog(ERROR, "getObjectDescription: Constraint %u does not exist",
1508+
elog(ERROR, "could not find tuple for constraint %u",
14951509
object->objectId);
14961510

14971511
con = (Form_pg_constraint) GETSTRUCT(tup);
@@ -1521,7 +1535,7 @@ getObjectDescription(const ObjectAddress *object)
15211535
ObjectIdGetDatum(object->objectId),
15221536
0, 0, 0);
15231537
if (!HeapTupleIsValid(conTup))
1524-
elog(ERROR, "getObjectDescription: Conversion %u does not exist",
1538+
elog(ERROR, "cache lookup failed for conversion %u",
15251539
object->objectId);
15261540
appendStringInfo(&buffer, "conversion %s",
15271541
NameStr(((Form_pg_conversion) GETSTRUCT(conTup))->conname));
@@ -1550,7 +1564,7 @@ getObjectDescription(const ObjectAddress *object)
15501564
tup = systable_getnext(adscan);
15511565

15521566
if (!HeapTupleIsValid(tup))
1553-
elog(ERROR, "getObjectDescription: Default %u does not exist",
1567+
elog(ERROR, "could not find tuple for attrdef %u",
15541568
object->objectId);
15551569

15561570
attrdef = (Form_pg_attrdef) GETSTRUCT(tup);
@@ -1575,7 +1589,7 @@ getObjectDescription(const ObjectAddress *object)
15751589
ObjectIdGetDatum(object->objectId),
15761590
0, 0, 0);
15771591
if (!HeapTupleIsValid(langTup))
1578-
elog(ERROR, "getObjectDescription: Language %u does not exist",
1592+
elog(ERROR, "cache lookup failed for language %u",
15791593
object->objectId);
15801594
appendStringInfo(&buffer, "language %s",
15811595
NameStr(((Form_pg_language) GETSTRUCT(langTup))->lanname));
@@ -1600,7 +1614,7 @@ getObjectDescription(const ObjectAddress *object)
16001614
ObjectIdGetDatum(object->objectId),
16011615
0, 0, 0);
16021616
if (!HeapTupleIsValid(opcTup))
1603-
elog(ERROR, "cache lookup of opclass %u failed",
1617+
elog(ERROR, "cache lookup failed for opclass %u",
16041618
object->objectId);
16051619
opcForm = (Form_pg_opclass) GETSTRUCT(opcTup);
16061620

@@ -1618,7 +1632,7 @@ getObjectDescription(const ObjectAddress *object)
16181632
ObjectIdGetDatum(opcForm->opcamid),
16191633
0, 0, 0);
16201634
if (!HeapTupleIsValid(amTup))
1621-
elog(ERROR, "syscache lookup for AM %u failed",
1635+
elog(ERROR, "cache lookup failed for access method %u",
16221636
opcForm->opcamid);
16231637
amForm = (Form_pg_am) GETSTRUCT(amTup);
16241638

@@ -1650,7 +1664,7 @@ getObjectDescription(const ObjectAddress *object)
16501664
tup = systable_getnext(rcscan);
16511665

16521666
if (!HeapTupleIsValid(tup))
1653-
elog(ERROR, "getObjectDescription: Rule %u does not exist",
1667+
elog(ERROR, "could not find tuple for rule %u",
16541668
object->objectId);
16551669

16561670
rule = (Form_pg_rewrite) GETSTRUCT(tup);
@@ -1684,7 +1698,7 @@ getObjectDescription(const ObjectAddress *object)
16841698
tup = systable_getnext(tgscan);
16851699

16861700
if (!HeapTupleIsValid(tup))
1687-
elog(ERROR, "getObjectDescription: Trigger %u does not exist",
1701+
elog(ERROR, "could not find tuple for trigger %u",
16881702
object->objectId);
16891703

16901704
trig = (Form_pg_trigger) GETSTRUCT(tup);
@@ -1704,7 +1718,7 @@ getObjectDescription(const ObjectAddress *object)
17041718

17051719
nspname = get_namespace_name(object->objectId);
17061720
if (!nspname)
1707-
elog(ERROR, "getObjectDescription: Schema %u does not exist",
1721+
elog(ERROR, "cache lookup failed for namespace %u",
17081722
object->objectId);
17091723
appendStringInfo(&buffer, "schema %s", nspname);
17101724
break;
@@ -1736,7 +1750,7 @@ getRelationDescription(StringInfo buffer, Oid relid)
17361750
ObjectIdGetDatum(relid),
17371751
0, 0, 0);
17381752
if (!HeapTupleIsValid(relTup))
1739-
elog(ERROR, "cache lookup of relation %u failed", relid);
1753+
elog(ERROR, "cache lookup failed for relation %u", relid);
17401754
relForm = (Form_pg_class) GETSTRUCT(relTup);
17411755

17421756
/* Qualify the name if not visible in search path */

0 commit comments

Comments
 (0)