From 216311d590de4638997eb391722f915026a29e88 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 18 Jul 2003 23:20:33 +0000 Subject: First bits of work on error message editing. --- doc/src/sgml/sources.sgml | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/sources.sgml b/doc/src/sgml/sources.sgml index 7ebcd24e777..18fd7597de0 100644 --- a/doc/src/sgml/sources.sgml +++ b/doc/src/sgml/sources.sgml @@ -1,5 +1,5 @@ @@ -125,11 +125,12 @@ less -x4 Here is a more complex example: ereport(ERROR, - (errmsg("Unable to identify an operator %s %s %s", - format_type_be(arg1), - NameListToString(op), - format_type_be(arg2)), - errhint("Try explicitly casting the arguments to appropriate types"))); + (errcode(ERRCODE_AMBIGUOUS_FUNCTION), + errmsg("function %s is not unique", + func_signature_string(funcname, nargs, + actual_arg_types)), + errhint("Unable to choose a best candidate function. " + "You may need to add explicit typecasts."))); This illustrates the use of format codes to embed run-time values into a message text. Also, an optional hint message is provided. @@ -141,11 +142,14 @@ less -x4 errcode(sqlerrcode) specifies the SQLSTATE error identifier - code for the condition. If this is not specified, it defaults to - ERRCODE_INTERNAL_ERROR, which is a convenient default since - a large number of ereport calls are in fact for internal - can't happen conditions. But never use this default when - reporting user mistakes. + code for the condition. If this routine is not called, the error + identifier defaults to + ERRCODE_INTERNAL_ERROR when the error level is + ERROR or higher, ERRCODE_WARNING when the + error level is WARNING, otherwise (for NOTICE + and below) ERRCODE_SUCCESSFUL_COMPLETION. + While these defaults are often convenient, always think whether they + are appropriate before omitting the errcode() call. @@ -220,15 +224,25 @@ less -x4 query processing. + + + errcode_for_file_access() is a convenience function that + selects an appropriate SQLSTATE error identifier for a failure in a + file-access-related system call. It uses the saved + errno to determine which error code to generate. + Usually this should be used in combination with %m in the + primary error message text. + + You may also see uses of the older function elog. This is equivalent to an ereport call specifying only severity - level and primary message. Because the error code always defaults to - ERRCODE_INTERNAL_ERROR, elog should only be - used for internal errors. + level and primary message. elog should only be used if + the default errcode assignment is appropriate; this generally restricts + its use to internal errors and debug logging output. @@ -270,7 +284,7 @@ less -x4 write Primary: could not create shared memory segment: %m - Detail: Failed syscall was shmget(key=%d, size=%u, 0%o) + Detail: Failed syscall was shmget(key=%d, size=%u, 0%o). Hint: the addendum -- cgit v1.2.3