diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 13ae6ad..37bfd6a 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2265,7 +2265,10 @@ getBaseTypeAndTypmod(Oid typid, int32 *typmod) tup = SearchSysCache1(TYPEOID, ObjectIdGetDatum(typid)); if (!HeapTupleIsValid(tup)) - elog(ERROR, "cache lookup failed for type %u", typid); + ereport(ERROR, + (errcode(ERRCODE_UNDEFINED_OBJECT), + errmsg("type with OID %u does not exist", + typid))); typTup = (Form_pg_type) GETSTRUCT(tup); if (typTup->typtype != TYPTYPE_DOMAIN) { diff --git a/src/backend/utils/cache/typcache.c b/src/backend/utils/cache/typcache.c index ea6f787..98db0db 100644 --- a/src/backend/utils/cache/typcache.c +++ b/src/backend/utils/cache/typcache.c @@ -231,7 +231,10 @@ lookup_type_cache(Oid type_id, int flags) tp = SearchSysCache1(TYPEOID, ObjectIdGetDatum(type_id)); if (!HeapTupleIsValid(tp)) - elog(ERROR, "cache lookup failed for type %u", type_id); + ereport(ERROR, + (errcode(ERRCODE_UNDEFINED_OBJECT), + errmsg("type with OID %u does not exist", + type_id))); typtup = (Form_pg_type) GETSTRUCT(tp); if (!typtup->typisdefined) ereport(ERROR, diff --git a/src/backend/utils/fmgr/fmgr.c b/src/backend/utils/fmgr/fmgr.c index 7e6a60d..231425b 100644 --- a/src/backend/utils/fmgr/fmgr.c +++ b/src/backend/utils/fmgr/fmgr.c @@ -2509,7 +2509,9 @@ CheckFunctionValidatorAccess(Oid validatorOid, Oid functionOid) /* Get the function's pg_proc entry */ procTup = SearchSysCache1(PROCOID, ObjectIdGetDatum(functionOid)); if (!HeapTupleIsValid(procTup)) - elog(ERROR, "cache lookup failed for function %u", functionOid); + ereport(ERROR, + (errcode(ERRCODE_UNDEFINED_FUNCTION), + errmsg("function with OID %u does not exist", functionOid))); procStruct = (Form_pg_proc) GETSTRUCT(procTup); /* diff --git a/src/test/regress/expected/errors.out b/src/test/regress/expected/errors.out index 210e5ff..48e2e29 100644 --- a/src/test/regress/expected/errors.out +++ b/src/test/regress/expected/errors.out @@ -447,3 +447,16 @@ create function infinite_recurse() returns int as \set VERBOSITY terse select infinite_recurse(); ERROR: stack depth limit exceeded +-- +-- Test error message by calling functions with invalid OID. +-- should get an appropriate error not cache lookup failure error +-- +-- passing invalid OID (1) to record_in +select pg_catalog.record_in(cast(pg_catalog.numerictypmodout(cast(98 as integer)) as cstring), cast(1 as oid), cast(35 as integer)); +ERROR: type with OID 1 does not exist +--passing invalid OID(10) to fmgr_c_validator +select pg_catalog.fmgr_c_validator(10); +ERROR: function with OID 10 does not exist +--passing invalid OID(10) to pg_catalog.domain_in +select pg_catalog.domain_in(cast(null as cstring),cast(10 as oid),cast(53 as integer)); +ERROR: type with OID 10 does not exist diff --git a/src/test/regress/sql/errors.sql b/src/test/regress/sql/errors.sql index cd370b4..52e992a 100644 --- a/src/test/regress/sql/errors.sql +++ b/src/test/regress/sql/errors.sql @@ -371,3 +371,18 @@ create function infinite_recurse() returns int as 'select infinite_recurse()' language sql; \set VERBOSITY terse select infinite_recurse(); + +-- +-- Test error message by calling functions with invalid OID. +-- should get an appropriate error not cache lookup failure error +-- + +-- passing invalid OID (1) to record_in +select pg_catalog.record_in(cast(pg_catalog.numerictypmodout(cast(98 as integer)) as cstring), cast(1 as oid), cast(35 as integer)); + +--passing invalid OID(10) to fmgr_c_validator +select pg_catalog.fmgr_c_validator(10); + +--passing invalid OID(10) to pg_catalog.domain_in +select pg_catalog.domain_in(cast(null as cstring),cast(10 as oid),cast(53 as integer)); +