Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb6a1d25

Browse files
committed
Error message editing in utils/adt. Again thanks to Joe Conway for doing
the bulk of the heavy lifting ...
1 parent524cfad commitb6a1d25

File tree

79 files changed

+2140
-1080
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+2140
-1080
lines changed

‎src/backend/utils/adt/acl.c

Lines changed: 79 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.91 2003/06/2700:33:25 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.92 2003/07/2704:53:02 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -90,8 +90,12 @@ getid(const char *s, char *n)
9090
else
9191
{
9292
if (len >=NAMEDATALEN-1)
93-
elog(ERROR,"identifier must be less than %d characters",
94-
NAMEDATALEN);
93+
ereport(ERROR,
94+
(errcode(ERRCODE_NAME_TOO_LONG),
95+
errmsg("identifier too long"),
96+
errdetail("Identifier must be less than %d characters.",
97+
NAMEDATALEN)));
98+
9599
n[len++]=*s;
96100
}
97101
}
@@ -157,26 +161,34 @@ aclparse(const char *s, AclItem *aip)
157161
Assert(s&&aip);
158162

159163
#ifdefACLDEBUG
160-
elog(LOG,"aclparse: input ='%s'",s);
164+
elog(LOG,"aclparse: input =\"%s\"",s);
161165
#endif
162166
idtype=ACL_IDTYPE_UID;
163167
s=getid(s,name);
164168
if (*s!='=')
165169
{
166170
/* we just read a keyword, not a name */
167-
if (strncmp(name,ACL_IDTYPE_GID_KEYWORD,sizeof(name))==0)
171+
if (strcmp(name,ACL_IDTYPE_GID_KEYWORD)==0)
168172
idtype=ACL_IDTYPE_GID;
169-
elseif (strncmp(name,ACL_IDTYPE_UID_KEYWORD,sizeof(name))!=0)
170-
elog(ERROR,"aclparse: bad keyword, must be [group|user]");
173+
elseif (strcmp(name,ACL_IDTYPE_UID_KEYWORD)!=0)
174+
ereport(ERROR,
175+
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
176+
errmsg("unrecognized keyword: \"%s\"",name),
177+
errhint("ACL keyword must be \"group\" or \"user\".")));
171178
s=getid(s,name);/* move s to the name beyond the keyword */
172179
if (name[0]=='\0')
173-
elog(ERROR,"aclparse: a name must follow the [group|user] keyword");
180+
ereport(ERROR,
181+
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
182+
errmsg("missing name"),
183+
errhint("A name must follow the [group|user] keyword.")));
174184
}
175185
if (name[0]=='\0')
176186
idtype=ACL_IDTYPE_WORLD;
177187

178188
if (*s!='=')
179-
elog(ERROR,"aclparse: expecting \"=\" sign");
189+
ereport(ERROR,
190+
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
191+
errmsg("missing \"=\" sign")));
180192

181193
privs=goption=ACL_NO_RIGHTS;
182194

@@ -221,8 +233,10 @@ aclparse(const char *s, AclItem *aip)
221233
read=ACL_CREATE_TEMP;
222234
break;
223235
default:
224-
elog(ERROR,"aclparse: mode flags must use \"%s\"",
225-
ACL_ALL_RIGHTS_STR);
236+
ereport(ERROR,
237+
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
238+
errmsg("invalid mode character: must be one of \"%s\"",
239+
ACL_ALL_RIGHTS_STR)));
226240
}
227241

228242
privs |=read;
@@ -247,14 +261,18 @@ aclparse(const char *s, AclItem *aip)
247261
{
248262
s=getid(s+1,name2);
249263
if (name2[0]=='\0')
250-
elog(ERROR,"aclparse: a name must follow the \"/\" sign");
264+
ereport(ERROR,
265+
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
266+
errmsg("a name must follow the \"/\" sign")));
251267

252268
aip->ai_grantor=get_usesysid(name2);
253269
}
254270
else
255271
{
256272
aip->ai_grantor=BOOTSTRAP_USESYSID;
257-
elog(WARNING,"defaulting grantor to %u",BOOTSTRAP_USESYSID);
273+
ereport(WARNING,
274+
(errcode(ERRCODE_INVALID_GRANTOR),
275+
errmsg("defaulting grantor to %u",BOOTSTRAP_USESYSID)));
258276
}
259277

260278
ACLITEM_SET_PRIVS_IDTYPE(*aip,privs,goption,idtype);
@@ -280,7 +298,7 @@ allocacl(int n)
280298
Sizesize;
281299

282300
if (n<0)
283-
elog(ERROR,"allocacl:invalid size: %d",n);
301+
elog(ERROR,"invalid size: %d",n);
284302
size=ACL_N_SIZE(n);
285303
new_acl= (Acl*)palloc0(size);
286304
new_acl->size=size;
@@ -311,7 +329,10 @@ aclitemin(PG_FUNCTION_ARGS)
311329
while (isspace((unsignedchar)*s))
312330
++s;
313331
if (*s)
314-
elog(ERROR,"aclitemin: extra garbage at end of specification");
332+
ereport(ERROR,
333+
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
334+
errmsg("extra garbage at the end of the ACL specification")));
335+
315336
PG_RETURN_ACLITEM_P(aip);
316337
}
317338

@@ -373,8 +394,8 @@ aclitemout(PG_FUNCTION_ARGS)
373394
caseACL_IDTYPE_WORLD:
374395
break;
375396
default:
376-
elog(ERROR,"aclitemout: bad idtype: %d",
377-
ACLITEM_GET_IDTYPE(*aip));
397+
elog(ERROR,"unrecognized idtype: %d",
398+
(int)ACLITEM_GET_IDTYPE(*aip));
378399
break;
379400
}
380401
while (*p)
@@ -482,7 +503,7 @@ acldefault(GrantObjectType objtype, AclId ownerid)
482503
owner_default=ACL_ALL_RIGHTS_NAMESPACE;
483504
break;
484505
default:
485-
elog(ERROR,"acldefault: bogusobjtype %d", (int)objtype);
506+
elog(ERROR,"unrecognizedobjtype: %d", (int)objtype);
486507
world_default=ACL_NO_RIGHTS;/* keep compiler quiet */
487508
owner_default=ACL_NO_RIGHTS;
488509
break;
@@ -644,7 +665,10 @@ recursive_revoke(Acl *acl,
644665
AclItemmod_acl;
645666

646667
if (behavior==DROP_RESTRICT)
647-
elog(ERROR,"dependent privileges exist (use CASCADE to revoke them too)");
668+
ereport(ERROR,
669+
(errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
670+
errmsg("dependent privileges exist"),
671+
errhint("Use CASCADE to revoke them too.")));
648672

649673
mod_acl.ai_grantor=grantee;
650674
mod_acl.ai_grantee=aip[i].ai_grantee;
@@ -718,7 +742,9 @@ aclremove(PG_FUNCTION_ARGS)
718742
new_aip=ACL_DAT(new_acl);
719743
if (dst==0)
720744
{/* start */
721-
elog(ERROR,"aclremove: removal of the world ACL??");
745+
ereport(ERROR,
746+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
747+
errmsg("cannot remove the world ACL")));
722748
}
723749
elseif (dst==old_num-1)
724750
{/* end */
@@ -784,7 +810,9 @@ makeaclitem(PG_FUNCTION_ARGS)
784810
}
785811
elseif (u_grantee!=0&&g_grantee!=0)
786812
{
787-
elog(ERROR,"cannot specify both user and group");
813+
ereport(ERROR,
814+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
815+
errmsg("cannot specify both user and group")));
788816
}
789817
elseif (u_grantee!=0)
790818
{
@@ -840,7 +868,9 @@ convert_priv_string(text *priv_type_text)
840868
if (strcasecmp(priv_type,"TEMPORARY")==0)
841869
returnACL_CREATE_TEMP;
842870

843-
elog(ERROR,"invalid privilege type %s",priv_type);
871+
ereport(ERROR,
872+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
873+
errmsg("unrecognized privilege type: \"%s\"",priv_type)));
844874
returnACL_NO_RIGHTS;/* keep compiler quiet */
845875
}
846876

@@ -1063,8 +1093,9 @@ convert_table_priv_string(text *priv_type_text)
10631093
if (strcasecmp(priv_type,"TRIGGER WITH GRANT OPTION")==0)
10641094
returnACL_GRANT_OPTION_FOR(ACL_TRIGGER);
10651095

1066-
elog(ERROR,"has_table_privilege: invalid privilege type %s",
1067-
priv_type);
1096+
ereport(ERROR,
1097+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1098+
errmsg("unrecognized privilege type: \"%s\"",priv_type)));
10681099
returnACL_NO_RIGHTS;/* keep compiler quiet */
10691100
}
10701101

@@ -1237,7 +1268,9 @@ convert_database_name(text *databasename)
12371268

12381269
oid=get_database_oid(dbname);
12391270
if (!OidIsValid(oid))
1240-
elog(ERROR,"database \"%s\" does not exist",dbname);
1271+
ereport(ERROR,
1272+
(errcode(ERRCODE_UNDEFINED_DATABASE),
1273+
errmsg("database \"%s\" does not exist",dbname)));
12411274

12421275
returnoid;
12431276
}
@@ -1272,8 +1305,9 @@ convert_database_priv_string(text *priv_type_text)
12721305
if (strcasecmp(priv_type,"TEMP WITH GRANT OPTION")==0)
12731306
returnACL_GRANT_OPTION_FOR(ACL_CREATE_TEMP);
12741307

1275-
elog(ERROR,"has_database_privilege: invalid privilege type %s",
1276-
priv_type);
1308+
ereport(ERROR,
1309+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1310+
errmsg("unrecognized privilege type: \"%s\"",priv_type)));
12771311
returnACL_NO_RIGHTS;/* keep compiler quiet */
12781312
}
12791313

@@ -1448,7 +1482,9 @@ convert_function_name(text *functionname)
14481482
CStringGetDatum(funcname)));
14491483

14501484
if (!OidIsValid(oid))
1451-
elog(ERROR,"function \"%s\" does not exist",funcname);
1485+
ereport(ERROR,
1486+
(errcode(ERRCODE_UNDEFINED_FUNCTION),
1487+
errmsg("function \"%s\" does not exist",funcname)));
14521488

14531489
returnoid;
14541490
}
@@ -1473,8 +1509,9 @@ convert_function_priv_string(text *priv_type_text)
14731509
if (strcasecmp(priv_type,"EXECUTE WITH GRANT OPTION")==0)
14741510
returnACL_GRANT_OPTION_FOR(ACL_EXECUTE);
14751511

1476-
elog(ERROR,"has_function_privilege: invalid privilege type %s",
1477-
priv_type);
1512+
ereport(ERROR,
1513+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1514+
errmsg("unrecognized privilege type: \"%s\"",priv_type)));
14781515
returnACL_NO_RIGHTS;/* keep compiler quiet */
14791516
}
14801517

@@ -1649,7 +1686,9 @@ convert_language_name(text *languagename)
16491686
CStringGetDatum(langname),
16501687
0,0,0);
16511688
if (!OidIsValid(oid))
1652-
elog(ERROR,"language \"%s\" does not exist",langname);
1689+
ereport(ERROR,
1690+
(errcode(ERRCODE_UNDEFINED_OBJECT),
1691+
errmsg("language \"%s\" does not exist",langname)));
16531692

16541693
returnoid;
16551694
}
@@ -1674,8 +1713,9 @@ convert_language_priv_string(text *priv_type_text)
16741713
if (strcasecmp(priv_type,"USAGE WITH GRANT OPTION")==0)
16751714
returnACL_GRANT_OPTION_FOR(ACL_USAGE);
16761715

1677-
elog(ERROR,"has_language_privilege: invalid privilege type %s",
1678-
priv_type);
1716+
ereport(ERROR,
1717+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1718+
errmsg("unrecognized privilege type: \"%s\"",priv_type)));
16791719
returnACL_NO_RIGHTS;/* keep compiler quiet */
16801720
}
16811721

@@ -1850,7 +1890,9 @@ convert_schema_name(text *schemaname)
18501890
CStringGetDatum(nspname),
18511891
0,0,0);
18521892
if (!OidIsValid(oid))
1853-
elog(ERROR,"schema \"%s\" does not exist",nspname);
1893+
ereport(ERROR,
1894+
(errcode(ERRCODE_UNDEFINED_SCHEMA),
1895+
errmsg("schema \"%s\" does not exist",nspname)));
18541896

18551897
returnoid;
18561898
}
@@ -1880,7 +1922,8 @@ convert_schema_priv_string(text *priv_type_text)
18801922
if (strcasecmp(priv_type,"USAGE WITH GRANT OPTION")==0)
18811923
returnACL_GRANT_OPTION_FOR(ACL_USAGE);
18821924

1883-
elog(ERROR,"has_schema_privilege: invalid privilege type %s",
1884-
priv_type);
1925+
ereport(ERROR,
1926+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1927+
errmsg("unrecognized privilege type: \"%s\"",priv_type)));
18851928
returnACL_NO_RIGHTS;/* keep compiler quiet */
18861929
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp