Make some sanity-check elogs more verbose
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Mon, 23 Nov 2020 16:10:03 +0000 (13:10 -0300)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Mon, 23 Nov 2020 16:10:03 +0000 (13:10 -0300)
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: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAMsr+YH7Kd87A3cU5m_wKo46HPQ46zFv5wesFNL0YWxkGhGv3g@mail.gmail.com

src/backend/utils/fmgr/funcapi.c

index b9efa7729152e8b41e23400e2bb467b2d1ec9f01..9696c88f2415c4073ae57ea7344aded4a3de698f 100644 (file)
@@ -1123,7 +1123,7 @@ get_func_arg_info(HeapTuple procTup,
            numargs < 0 ||
            ARR_HASNULL(arr) ||
            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);
        *p_argtypes = (Oid *) palloc(numargs * sizeof(Oid));
        memcpy(*p_argtypes, ARR_DATA_PTR(arr),
@@ -1170,7 +1170,8 @@ get_func_arg_info(HeapTuple procTup,
            ARR_DIMS(arr)[0] != numargs ||
            ARR_HASNULL(arr) ||
            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));
        memcpy(*p_argmodes, ARR_DATA_PTR(arr),
               numargs * sizeof(char));
@@ -1210,7 +1211,7 @@ get_func_trftypes(HeapTuple procTup,
            nelems < 0 ||
            ARR_HASNULL(arr) ||
            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);
        *p_trftypes = (Oid *) palloc(nelems * sizeof(Oid));
        memcpy(*p_trftypes, ARR_DATA_PTR(arr),
@@ -1261,7 +1262,7 @@ get_func_input_arg_names(char prokind,
    if (ARR_NDIM(arr) != 1 ||
        ARR_HASNULL(arr) ||
        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,
                      &argnames, NULL, &numargs);
    if (proargmodes != PointerGetDatum(NULL))
@@ -1271,7 +1272,8 @@ get_func_input_arg_names(char prokind,
            ARR_DIMS(arr)[0] != numargs ||
            ARR_HASNULL(arr) ||
            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);
    }
    else
@@ -1368,14 +1370,15 @@ get_func_result_name(Oid functionId)
            numargs < 0 ||
            ARR_HASNULL(arr) ||
            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);
        arr = DatumGetArrayTypeP(proargnames);  /* ensure not toasted */
        if (ARR_NDIM(arr) != 1 ||
            ARR_DIMS(arr)[0] != numargs ||
            ARR_HASNULL(arr) ||
            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,
                          &argnames, NULL, &nargnames);
        Assert(nargnames == numargs);
@@ -1506,14 +1509,15 @@ build_function_result_tupdesc_d(char prokind,
        numargs < 0 ||
        ARR_HASNULL(arr) ||
        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);
    arr = DatumGetArrayTypeP(proargmodes);  /* ensure not toasted */
    if (ARR_NDIM(arr) != 1 ||
        ARR_DIMS(arr)[0] != numargs ||
        ARR_HASNULL(arr) ||
        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);
    if (proargnames != PointerGetDatum(NULL))
    {
@@ -1522,7 +1526,8 @@ build_function_result_tupdesc_d(char prokind,
            ARR_DIMS(arr)[0] != numargs ||
            ARR_HASNULL(arr) ||
            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,
                          &argnames, NULL, &nargnames);
        Assert(nargnames == numargs);