RFC: error_codes
| From: | (Marcus Börger) | Date: | Tue, 03 Dec 2002 15:41:55 +0000 |
| Subject: | RFC: error_codes | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-92038@lists.php.net to get a copy of this message | ||
After main discussion about this seems over here is a proposal for error codes.
When the solution is accepted by the majority i will commit it and write something
together in CODING_STANDARDS. Maybe i can receive some notes on that, too.
marcus
Here is an example output (error_code="EXIF-006"):
[marcus@zaphod php4-HEAD]$ sapi/cli/php -d exif.encode_unicode=vx
Unknown(0) : Warning - Unknown(): <EXIF-006> Illegal encoding ignored: 'vx'
Here is the patch:
cvs -z3 -q diff main.c php.h (in directory S:\php4-HEAD\main\)
Index: main.c
===================================================================
RCS file: /repository/php4/main/main.c,v
retrieving revision 1.518
diff -u -r1.518 main.c
--- main.c 21 Nov 2002 14:56:06 -0000 1.518 +++ main.c 3 Dec 2002 15:34:46 -0000@@ -385,18 +385,33 @@ /* }}} */ /* {{{ php_verror */ -/* php_verror is called from php_error_docref<n> functions. +/* php_verror is called from php_error_docref<n> functions and + * calls itself php_verror_ex with NO error_code. + */ +PHPAPI void php_verror(const char *docref, const char *params, int type, const char *format, va_list args TSRMLS_DC) +{
+ php_verror_ex(NULL, docref, params, type, format, args TSRMLS_CC);+} +/* }}} */ + +/* {{{ php_verror_ex */ +/* php_verror_ex is called from php_error_docref<n> and php_error_ex<n> functions. * Its purpose is to unify error messages and automatically generate clickable * html error messages if correcponding ini setting (html_errors) is activated. * See: CODING_STANDARDS for details. */ -PHPAPI void php_verror(const char *docref, const char *params, int type, const char *format, va_list args TSRMLS_DC) +PHPAPI void php_verror_ex(const char *error_code, const char *docref, const char *params, int type, const char *format, va_list args TSRMLS_DC) {
char *buffer = NULL, *docref_buf = NULL, *ref = NULL, *target = NULL;
char *docref_target = "", *docref_root = "";
char *function, *p;
+ char *error_code_separator1 = error_code ? "<" : "";
+ char *error_code_separator2 = error_code ? "> " : "";
int buffer_len = 0;
-
+
+ if (!error_code) {
+ error_code = "";
+ }
buffer_len = vspprintf(&buffer, 0, format, args);
if (buffer) {
if (docref && docref[0] == '#') {
@@ -442,9 +457,9 @@
}
}
if (PG(html_errors)) {
- php_error(type, "%s(%s) [<a href='%s%s%s'>%s</a>]: %s", get_active_function_name(TSRMLS_C), params, docref_root, docref, docref_target, docref, buffer);
+ php_error(type, "%s(%s) [<a href='%s%s%s'>%s</a>]: %s%s%s%s", get_active_function_name(TSRMLS_C), params, docref_root, docref, docref_target, docref, error_code_separator1, error_code, error_code_separator2, buffer);
} else {
- php_error(type, "%s(%s) [%s%s%s]: %s", get_active_function_name(TSRMLS_C), params, docref_root, docref, docref_target, buffer);
+ php_error(type, "%s(%s) [%s%s%s]: %s%s%s%s", get_active_function_name(TSRMLS_C), params, docref_root, docref, docref_target, error_code_separator1, error_code, error_code_separator2, buffer);
}
if (target) {
efree(target);
@@ -453,7 +468,7 @@
docref = get_active_function_name(TSRMLS_C);
if (!docref)
docref = "Unknown";
- php_error(type, "%s(%s): %s", docref, params, buffer);
+ php_error(type, "%s(%s): %s%s%s%s", docref, params, error_code_separator1, error_code, error_code_separator2, buffer);
}
if (PG(track_errors) && EG(active_symbol_table)) {
@@ -475,6 +490,18 @@
}
/* }}} */
+/* {{{ php_error_ex */
+/* See: CODING_STANDARDS for details. */
+PHPAPI void php_error_ex(const char *error_code, const char *docref TSRMLS_DC, int type, const char *format, ...)
+{
+ va_list args;+
+ va_start(args, format); + php_verror_ex(error_code, docref, "", type, format, args TSRMLS_CC); + va_end(args);+} +/* }}} */ + /* {{{ php_error_docref */ /* See: CODING_STANDARDS for details. */ PHPAPI void php_error_docref(const char *docref TSRMLS_DC, int type, const char *format, ...) @@ -487,6 +514,18 @@ } /* }}} */ +/* {{{ php_error_ex1 */ +/* See: CODING_STANDARDS for details. */ +PHPAPI void php_error_ex1(const char *error_code, const char *docref TSRMLS_DC, const char *param1, int type, const char *format, ...) +{
+ va_list args;+
+ va_start(args, format); + php_verror_ex(error_code, docref, param1, type, format, args TSRMLS_CC); + va_end(args);+} +/* }}} */ + /* {{{ php_error_docref1 */ /* See: CODING_STANDARDS for details. */ PHPAPI void php_error_docref1(const char *docref TSRMLS_DC, const char *param1, int type, const char *format, ...) @@ -499,6 +538,21 @@ } /* }}} */ +/* {{{ php_error_ex2 */ +/* See: CODING_STANDARDS for details. */ +PHPAPI void php_error_ex2(const char *error_code, const char *docref TSRMLS_DC, const char *param1, const char *param2, int type, const char *format, ...) +{
+ char *params; + va_list args;+
+ spprintf(¶ms, 0, "%s,%s", param1, param2); + va_start(args, format); + php_verror_ex(error_code, docref, params ? params : "...", type, format, args TSRMLS_CC); + va_end(args); + if (params) + efree(params);+} +/* }}} */ /* {{{ php_error_docref2 */ /* See: CODING_STANDARDS for details. */ PHPAPI void php_error_docref2(const char *docref TSRMLS_DC, const char *param1, const char *param2, int type, const char *format, ...) Index: php.h =================================================================== RCS file: /repository/php4/main/php.h,v retrieving revision 1.178 diff -u -r1.178 php.h
--- php.h 7 Nov 2002 11:52:45 -0000 1.178 +++ php.h 3 Dec 2002 15:34:46 -0000@@ -274,7 +274,8 @@ #define php_error zend_error -PHPAPI void php_verror(const char *docref, const char *params, int type, const char *format, va_list args TSRMLS_DC) ; +PHPAPI void php_verror(const char *docref, const char *params, int type, const char *format, va_list args TSRMLS_DC); +PHPAPI void php_verror_ex(const char *error_code, const char *docref, const char *params, int type, const char *format, va_list args TSRMLS_DC); /* PHPAPI void php_error(int type, const char *format, ...); */ PHPAPI void php_error_docref0(const char *docref TSRMLS_DC, int type, const char *format, ...); @@ -282,6 +283,13 @@ PHPAPI void php_error_docref2(const char *docref TSRMLS_DC, const char *param1, const char *param2, int type, const char *format, ...); #define php_error_docref php_error_docref0 + +/* PHPAPI void php_error(int type, const char *format, ...); */ +PHPAPI void php_error_ex0(const char *error_code, const char *docref TSRMLS_DC, int type, const char *format, ...); +PHPAPI void php_error_ex1(const char *error_code, const char *docref TSRMLS_DC, const char *param1, int type, const char *format, ...); +PHPAPI void php_error_ex2(const char *error_code, const char *docref TSRMLS_DC, const char *param1, const char *param2, int type, const char *format, ...); + +#define php_error_ex php_error_ex0 #define zenderror phperror #define zendlex phplex