mirror of
https://github.com/postgres/postgres.git
synced 2026-10-23 13:29:09 +03:00
Improve error code and messages for some SQL-reachable code paths
The error code paths adjusted in this commit are reachable via SQL functions that are documented. Previously, they generated an internal error code, causing the messages to not be translated. They are now upgraded with a suitable error code. Note the extra consistency in the three typmod errors, and the tweaks in acldefault_sql() to show correctly non-printable characters. Author: Alexander Lakhin <exclusion@gmail.com> Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/94ac928b-8370-4db5-ada5-579a9ebc089d@gmail.com
This commit is contained in:
@@ -4123,7 +4123,9 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok)
|
||||
}
|
||||
|
||||
default:
|
||||
elog(ERROR, "unsupported object class: %u", object->classId);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("unsupported object class: %u", object->classId)));
|
||||
}
|
||||
|
||||
/* an empty buffer is equivalent to no object found */
|
||||
|
||||
@@ -9621,6 +9621,7 @@ ATPrepAddPrimaryKey(List **wqueue, Relation rel, AlterTableCmd *cmd,
|
||||
tup = findNotNullConstraint(childrelid, strVal(column));
|
||||
if (!tup)
|
||||
ereport(ERROR,
|
||||
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
|
||||
errmsg("column \"%s\" of table \"%s\" is not marked NOT NULL",
|
||||
strVal(column), get_rel_name(childrelid)));
|
||||
/* verify it's good enough */
|
||||
|
||||
@@ -805,8 +805,10 @@ transformColumnDefinition(CreateStmtContext *cxt, ColumnDef *column)
|
||||
if (constraint->conname &&
|
||||
notnull_constraint->conname &&
|
||||
strcmp(notnull_constraint->conname, constraint->conname) != 0)
|
||||
elog(ERROR, "conflicting not-null constraint names \"%s\" and \"%s\"",
|
||||
notnull_constraint->conname, constraint->conname);
|
||||
ereport(ERROR,
|
||||
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
|
||||
errmsg("conflicting not-null constraint names \"%s\" and \"%s\"",
|
||||
notnull_constraint->conname, constraint->conname));
|
||||
|
||||
if (notnull_constraint->is_no_inherit != constraint->is_no_inherit)
|
||||
ereport(ERROR,
|
||||
|
||||
@@ -1228,7 +1228,9 @@ pg_get_shmem_allocations_numa(PG_FUNCTION_ARGS)
|
||||
Size *nodes;
|
||||
|
||||
if (pg_numa_init() == -1)
|
||||
elog(ERROR, "libnuma initialization failed or NUMA is not supported on this platform");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("libnuma initialization failed or NUMA is not supported on this platform")));
|
||||
|
||||
InitMaterializedSRF(fcinfo, 0);
|
||||
|
||||
|
||||
@@ -989,7 +989,16 @@ acldefault_sql(PG_FUNCTION_ARGS)
|
||||
objtype = OBJECT_TYPE;
|
||||
break;
|
||||
default:
|
||||
elog(ERROR, "unrecognized object type abbreviation: %c", objtypec);
|
||||
/* Avoid printing non-ASCII bytes, else we have encoding issues */
|
||||
if (objtypec >= ' ' && objtypec < 0x7f)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("unrecognized object type abbreviation: \"%c\"", objtypec)));
|
||||
else /* use \ooo format, like charout() */
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("unrecognized object type abbreviation: \"\\%03o\"",
|
||||
(unsigned char) objtypec)));
|
||||
}
|
||||
|
||||
PG_RETURN_ACL_P(acldefault(objtype, owner));
|
||||
|
||||
@@ -1186,7 +1186,9 @@ intervaltypmodout(PG_FUNCTION_ARGS)
|
||||
fieldstr = "";
|
||||
break;
|
||||
default:
|
||||
elog(ERROR, "invalid INTERVAL typmod: 0x%x", typmod);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("unrecognized interval typmod: %d", typmod)));
|
||||
fieldstr = "";
|
||||
break;
|
||||
}
|
||||
@@ -1246,7 +1248,9 @@ intervaltypmodleastfield(int32 typmod)
|
||||
case INTERVAL_FULL_RANGE:
|
||||
return 0; /* SECOND */
|
||||
default:
|
||||
elog(ERROR, "invalid INTERVAL typmod: 0x%x", typmod);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("unrecognized interval typmod: %d", typmod)));
|
||||
break;
|
||||
}
|
||||
return 0; /* can't get here, but keep compiler quiet */
|
||||
@@ -1489,7 +1493,9 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod,
|
||||
/* fractional-second rounding will be dealt with below */
|
||||
}
|
||||
else
|
||||
elog(ERROR, "unrecognized interval typmod: %d", typmod);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("unrecognized interval typmod: %d", typmod)));
|
||||
|
||||
/* Need to adjust sub-second precision? */
|
||||
if (precision != INTERVAL_FULL_PRECISION)
|
||||
|
||||
@@ -393,7 +393,9 @@ comp_option : '#' K_OPTION K_DUMP
|
||||
else if (strcmp($3, "off") == 0)
|
||||
plpgsql_curr_compile->print_strict_params = false;
|
||||
else
|
||||
elog(ERROR, "unrecognized print_strict_params option %s", $3);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("unrecognized %s option \"%s\"", "print_strict_params", $3)));
|
||||
}
|
||||
| '#' K_VARIABLE_CONFLICT K_ERROR
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user