aboutsummaryrefslogtreecommitdiff
path: root/src/backend/tcop/fastpath.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2003-07-22 19:00:12 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2003-07-22 19:00:12 +0000
commitb05d3ae1edf557e174f80624219854767963dc66 (patch)
tree204def9d6f61d82a5816275df9384d209ad12d55 /src/backend/tcop/fastpath.c
parent277dbb0c34791fe2f6192d02ea577d3738666c2f (diff)
downloadpostgresql-b05d3ae1edf557e174f80624219854767963dc66.tar.gz
postgresql-b05d3ae1edf557e174f80624219854767963dc66.zip
Error message editing in backend/libpq, backend/postmaster, backend/tcop.
Along the way, fix some logic problems in pgstat_initstats, notably the bogus assumption that malloc returns zeroed memory.
Diffstat (limited to 'src/backend/tcop/fastpath.c')
-rw-r--r--src/backend/tcop/fastpath.c83
1 files changed, 54 insertions, 29 deletions
diff --git a/src/backend/tcop/fastpath.c b/src/backend/tcop/fastpath.c
index 37b7c3d8d9d..7ab856d6131 100644
--- a/src/backend/tcop/fastpath.c
+++ b/src/backend/tcop/fastpath.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/tcop/fastpath.c,v 1.64 2003/05/09 18:18:54 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/tcop/fastpath.c,v 1.65 2003/07/22 19:00:11 tgl Exp $
*
* NOTES
* This cruft is the server side of PQfn.
@@ -101,8 +101,10 @@ GetOldFunctionMessage(StringInfo buf)
if (argsize < -1)
{
/* FATAL here since no hope of regaining message sync */
- elog(FATAL, "HandleFunctionRequest: bogus argsize %d",
- argsize);
+ ereport(FATAL,
+ (errcode(ERRCODE_PROTOCOL_VIOLATION),
+ errmsg("invalid argument size %d in function call message",
+ argsize)));
}
/* and arg contents */
if (argsize > 0)
@@ -180,7 +182,9 @@ SendFunctionResult(Datum retval, bool isnull, Oid rettype, int16 format)
pfree(outputbytes);
}
else
- elog(ERROR, "Invalid format code %d", format);
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("unsupported format code: %d", format)));
}
if (!newstyle)
@@ -208,7 +212,7 @@ fetch_fp_info(Oid func_id, struct fp_info * fip)
* Since the validity of this structure is determined by whether the
* funcid is OK, we clear the funcid here. It must not be set to the
* correct value until we are about to return with a good struct
- * fp_info, since we can be interrupted (i.e., with an elog(ERROR,
+ * fp_info, since we can be interrupted (i.e., with an ereport(ERROR,
* ...)) at any time. [No longer really an issue since we don't save
* the struct fp_info across transactions anymore, but keep it
* anyway.]
@@ -222,8 +226,9 @@ fetch_fp_info(Oid func_id, struct fp_info * fip)
ObjectIdGetDatum(func_id),
0, 0, 0);
if (!HeapTupleIsValid(func_htp))
- elog(ERROR, "fetch_fp_info: cache lookup for function %u failed",
- func_id);
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_FUNCTION),
+ errmsg("function with OID %u does not exist", func_id)));
pp = (Form_pg_proc) GETSTRUCT(func_htp);
fip->namespace = pp->pronamespace;
@@ -254,8 +259,8 @@ fetch_fp_info(Oid func_id, struct fp_info * fip)
* RETURNS:
* 0 if successful completion, EOF if frontend connection lost.
*
- * Note: All ordinary errors result in elog(ERROR,...). However,
- * if we lose the frontend connection there is no one to elog to,
+ * Note: All ordinary errors result in ereport(ERROR,...). However,
+ * if we lose the frontend connection there is no one to ereport to,
* and no use in proceeding...
*
* Note: palloc()s done here and in the called function do not need to be
@@ -282,19 +287,23 @@ HandleFunctionRequest(StringInfo msgBuf)
{
if (GetOldFunctionMessage(msgBuf))
{
- elog(COMMERROR, "unexpected EOF on client connection");
+ ereport(COMMERROR,
+ (errcode(ERRCODE_PROTOCOL_VIOLATION),
+ errmsg("unexpected EOF on client connection")));
return EOF;
}
}
/*
* Now that we've eaten the input message, check to see if we actually
- * want to do the function call or not. It's now safe to elog(); we won't
- * lose sync with the frontend.
+ * want to do the function call or not. It's now safe to ereport();
+ * we won't lose sync with the frontend.
*/
if (IsAbortedTransactionBlockState())
- elog(ERROR, "current transaction is aborted, "
- "queries ignored until end of transaction block");
+ ereport(ERROR,
+ (errcode(ERRCODE_IN_FAILED_SQL_TRANSACTION),
+ errmsg("current transaction is aborted, "
+ "queries ignored until end of transaction block")));
/*
* Begin parsing the buffer contents.
@@ -404,14 +413,18 @@ parse_fcall_arguments(StringInfo msgBuf, struct fp_info *fip,
nargs = pq_getmsgint(msgBuf, 2); /* # of arguments */
if (fip->flinfo.fn_nargs != nargs || nargs > FUNC_MAX_ARGS)
- elog(ERROR, "HandleFunctionRequest: actual arguments (%d) != registered arguments (%d)",
- nargs, fip->flinfo.fn_nargs);
+ ereport(ERROR,
+ (errcode(ERRCODE_PROTOCOL_VIOLATION),
+ errmsg("function call message contains %d arguments but function requires %d",
+ nargs, fip->flinfo.fn_nargs)));
fcinfo->nargs = nargs;
if (numAFormats > 1 && numAFormats != nargs)
- elog(ERROR, "Function Call message has %d argument formats but %d arguments",
- numAFormats, nargs);
+ ereport(ERROR,
+ (errcode(ERRCODE_PROTOCOL_VIOLATION),
+ errmsg("function call message contains %d argument formats but %d arguments",
+ numAFormats, nargs)));
initStringInfo(&abuf);
@@ -430,8 +443,10 @@ parse_fcall_arguments(StringInfo msgBuf, struct fp_info *fip,
continue;
}
if (argsize < 0)
- elog(ERROR, "HandleFunctionRequest: bogus argsize %d",
- argsize);
+ ereport(ERROR,
+ (errcode(ERRCODE_PROTOCOL_VIOLATION),
+ errmsg("invalid argument size %d in function call message",
+ argsize)));
/* Reset abuf to empty, and insert raw data into it */
abuf.len = 0;
@@ -489,11 +504,15 @@ parse_fcall_arguments(StringInfo msgBuf, struct fp_info *fip,
/* Trouble if it didn't eat the whole buffer */
if (abuf.cursor != abuf.len)
- elog(ERROR, "Improper binary format in function argument %d",
- i + 1);
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
+ errmsg("incorrect binary data format in function argument %d",
+ i + 1)));
}
else
- elog(ERROR, "Invalid format code %d", aformat);
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("unsupported format code: %d", aformat)));
}
/* Return result format code */
@@ -517,8 +536,10 @@ parse_fcall_arguments_20(StringInfo msgBuf, struct fp_info *fip,
nargs = pq_getmsgint(msgBuf, 4); /* # of arguments */
if (fip->flinfo.fn_nargs != nargs || nargs > FUNC_MAX_ARGS)
- elog(ERROR, "HandleFunctionRequest: actual arguments (%d) != registered arguments (%d)",
- nargs, fip->flinfo.fn_nargs);
+ ereport(ERROR,
+ (errcode(ERRCODE_PROTOCOL_VIOLATION),
+ errmsg("function call message contains %d arguments but function requires %d",
+ nargs, fip->flinfo.fn_nargs)));
fcinfo->nargs = nargs;
@@ -545,8 +566,10 @@ parse_fcall_arguments_20(StringInfo msgBuf, struct fp_info *fip,
continue;
}
if (argsize < 0)
- elog(ERROR, "HandleFunctionRequest: bogus argsize %d",
- argsize);
+ ereport(ERROR,
+ (errcode(ERRCODE_PROTOCOL_VIOLATION),
+ errmsg("invalid argument size %d in function call message",
+ argsize)));
/* Reset abuf to empty, and insert raw data into it */
abuf.len = 0;
@@ -566,8 +589,10 @@ parse_fcall_arguments_20(StringInfo msgBuf, struct fp_info *fip,
/* Trouble if it didn't eat the whole buffer */
if (abuf.cursor != abuf.len)
- elog(ERROR, "Improper binary format in function argument %d",
- i + 1);
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
+ errmsg("incorrect binary data format in function argument %d",
+ i + 1)));
}
/* Desired result format is always binary in protocol 2.0 */