Commit fe051291 authored by Alvaro Herrera's avatar Alvaro Herrera

Make some sanity-check elogs more verbose

A few sanity checks in funcapi.c were not mentioning all the possible
clauses for failure, confusing developers who fat-fingered catalog data
additions.  Make the errors more detailed to avoid wasting time in
pinpointing mistakes.

Per complaint from Craig Ringer.
Reviewed-by: default avatarTom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAMsr+YH7Kd87A3cU5m_wKo46HPQ46zFv5wesFNL0YWxkGhGv3g@mail.gmail.com
parent 68b1a487
...@@ -1123,7 +1123,7 @@ get_func_arg_info(HeapTuple procTup, ...@@ -1123,7 +1123,7 @@ get_func_arg_info(HeapTuple procTup,
numargs < 0 || numargs < 0 ||
ARR_HASNULL(arr) || ARR_HASNULL(arr) ||
ARR_ELEMTYPE(arr) != OIDOID) ARR_ELEMTYPE(arr) != OIDOID)
elog(ERROR, "proallargtypes is not a 1-D Oid array"); elog(ERROR, "proallargtypes is not a 1-D Oid array or it contains nulls");
Assert(numargs >= procStruct->pronargs); Assert(numargs >= procStruct->pronargs);
*p_argtypes = (Oid *) palloc(numargs * sizeof(Oid)); *p_argtypes = (Oid *) palloc(numargs * sizeof(Oid));
memcpy(*p_argtypes, ARR_DATA_PTR(arr), memcpy(*p_argtypes, ARR_DATA_PTR(arr),
...@@ -1170,7 +1170,8 @@ get_func_arg_info(HeapTuple procTup, ...@@ -1170,7 +1170,8 @@ get_func_arg_info(HeapTuple procTup,
ARR_DIMS(arr)[0] != numargs || ARR_DIMS(arr)[0] != numargs ||
ARR_HASNULL(arr) || ARR_HASNULL(arr) ||
ARR_ELEMTYPE(arr) != CHAROID) ARR_ELEMTYPE(arr) != CHAROID)
elog(ERROR, "proargmodes is not a 1-D char array"); elog(ERROR, "proargmodes is not a 1-D char array of length %d or it contains nulls",
numargs);
*p_argmodes = (char *) palloc(numargs * sizeof(char)); *p_argmodes = (char *) palloc(numargs * sizeof(char));
memcpy(*p_argmodes, ARR_DATA_PTR(arr), memcpy(*p_argmodes, ARR_DATA_PTR(arr),
numargs * sizeof(char)); numargs * sizeof(char));
...@@ -1210,7 +1211,7 @@ get_func_trftypes(HeapTuple procTup, ...@@ -1210,7 +1211,7 @@ get_func_trftypes(HeapTuple procTup,
nelems < 0 || nelems < 0 ||
ARR_HASNULL(arr) || ARR_HASNULL(arr) ||
ARR_ELEMTYPE(arr) != OIDOID) ARR_ELEMTYPE(arr) != OIDOID)
elog(ERROR, "protrftypes is not a 1-D Oid array"); elog(ERROR, "protrftypes is not a 1-D Oid array or it contains nulls");
Assert(nelems >= ((Form_pg_proc) GETSTRUCT(procTup))->pronargs); Assert(nelems >= ((Form_pg_proc) GETSTRUCT(procTup))->pronargs);
*p_trftypes = (Oid *) palloc(nelems * sizeof(Oid)); *p_trftypes = (Oid *) palloc(nelems * sizeof(Oid));
memcpy(*p_trftypes, ARR_DATA_PTR(arr), memcpy(*p_trftypes, ARR_DATA_PTR(arr),
...@@ -1261,7 +1262,7 @@ get_func_input_arg_names(char prokind, ...@@ -1261,7 +1262,7 @@ get_func_input_arg_names(char prokind,
if (ARR_NDIM(arr) != 1 || if (ARR_NDIM(arr) != 1 ||
ARR_HASNULL(arr) || ARR_HASNULL(arr) ||
ARR_ELEMTYPE(arr) != TEXTOID) ARR_ELEMTYPE(arr) != TEXTOID)
elog(ERROR, "proargnames is not a 1-D text array"); elog(ERROR, "proargnames is not a 1-D text array or it contains nulls");
deconstruct_array(arr, TEXTOID, -1, false, TYPALIGN_INT, deconstruct_array(arr, TEXTOID, -1, false, TYPALIGN_INT,
&argnames, NULL, &numargs); &argnames, NULL, &numargs);
if (proargmodes != PointerGetDatum(NULL)) if (proargmodes != PointerGetDatum(NULL))
...@@ -1271,7 +1272,8 @@ get_func_input_arg_names(char prokind, ...@@ -1271,7 +1272,8 @@ get_func_input_arg_names(char prokind,
ARR_DIMS(arr)[0] != numargs || ARR_DIMS(arr)[0] != numargs ||
ARR_HASNULL(arr) || ARR_HASNULL(arr) ||
ARR_ELEMTYPE(arr) != CHAROID) ARR_ELEMTYPE(arr) != CHAROID)
elog(ERROR, "proargmodes is not a 1-D char array"); elog(ERROR, "proargmodes is not a 1-D char array of length %d or it contains nulls",
numargs);
argmodes = (char *) ARR_DATA_PTR(arr); argmodes = (char *) ARR_DATA_PTR(arr);
} }
else else
...@@ -1368,14 +1370,15 @@ get_func_result_name(Oid functionId) ...@@ -1368,14 +1370,15 @@ get_func_result_name(Oid functionId)
numargs < 0 || numargs < 0 ||
ARR_HASNULL(arr) || ARR_HASNULL(arr) ||
ARR_ELEMTYPE(arr) != CHAROID) ARR_ELEMTYPE(arr) != CHAROID)
elog(ERROR, "proargmodes is not a 1-D char array"); elog(ERROR, "proargmodes is not a 1-D char array or it contains nulls");
argmodes = (char *) ARR_DATA_PTR(arr); argmodes = (char *) ARR_DATA_PTR(arr);
arr = DatumGetArrayTypeP(proargnames); /* ensure not toasted */ arr = DatumGetArrayTypeP(proargnames); /* ensure not toasted */
if (ARR_NDIM(arr) != 1 || if (ARR_NDIM(arr) != 1 ||
ARR_DIMS(arr)[0] != numargs || ARR_DIMS(arr)[0] != numargs ||
ARR_HASNULL(arr) || ARR_HASNULL(arr) ||
ARR_ELEMTYPE(arr) != TEXTOID) ARR_ELEMTYPE(arr) != TEXTOID)
elog(ERROR, "proargnames is not a 1-D text array"); elog(ERROR, "proargnames is not a 1-D text array of length %d or it contains nulls",
numargs);
deconstruct_array(arr, TEXTOID, -1, false, TYPALIGN_INT, deconstruct_array(arr, TEXTOID, -1, false, TYPALIGN_INT,
&argnames, NULL, &nargnames); &argnames, NULL, &nargnames);
Assert(nargnames == numargs); Assert(nargnames == numargs);
...@@ -1506,14 +1509,15 @@ build_function_result_tupdesc_d(char prokind, ...@@ -1506,14 +1509,15 @@ build_function_result_tupdesc_d(char prokind,
numargs < 0 || numargs < 0 ||
ARR_HASNULL(arr) || ARR_HASNULL(arr) ||
ARR_ELEMTYPE(arr) != OIDOID) ARR_ELEMTYPE(arr) != OIDOID)
elog(ERROR, "proallargtypes is not a 1-D Oid array"); elog(ERROR, "proallargtypes is not a 1-D Oid array or it contains nulls");
argtypes = (Oid *) ARR_DATA_PTR(arr); argtypes = (Oid *) ARR_DATA_PTR(arr);
arr = DatumGetArrayTypeP(proargmodes); /* ensure not toasted */ arr = DatumGetArrayTypeP(proargmodes); /* ensure not toasted */
if (ARR_NDIM(arr) != 1 || if (ARR_NDIM(arr) != 1 ||
ARR_DIMS(arr)[0] != numargs || ARR_DIMS(arr)[0] != numargs ||
ARR_HASNULL(arr) || ARR_HASNULL(arr) ||
ARR_ELEMTYPE(arr) != CHAROID) ARR_ELEMTYPE(arr) != CHAROID)
elog(ERROR, "proargmodes is not a 1-D char array"); elog(ERROR, "proargmodes is not a 1-D char array of length %d or it contains nulls",
numargs);
argmodes = (char *) ARR_DATA_PTR(arr); argmodes = (char *) ARR_DATA_PTR(arr);
if (proargnames != PointerGetDatum(NULL)) if (proargnames != PointerGetDatum(NULL))
{ {
...@@ -1522,7 +1526,8 @@ build_function_result_tupdesc_d(char prokind, ...@@ -1522,7 +1526,8 @@ build_function_result_tupdesc_d(char prokind,
ARR_DIMS(arr)[0] != numargs || ARR_DIMS(arr)[0] != numargs ||
ARR_HASNULL(arr) || ARR_HASNULL(arr) ||
ARR_ELEMTYPE(arr) != TEXTOID) ARR_ELEMTYPE(arr) != TEXTOID)
elog(ERROR, "proargnames is not a 1-D text array"); elog(ERROR, "proargnames is not a 1-D text array of length %d or it contains nulls",
numargs);
deconstruct_array(arr, TEXTOID, -1, false, TYPALIGN_INT, deconstruct_array(arr, TEXTOID, -1, false, TYPALIGN_INT,
&argnames, NULL, &nargnames); &argnames, NULL, &nargnames);
Assert(nargnames == numargs); Assert(nargnames == numargs);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment