From 3b5b7f48848d098c6190781f8790a1b0dcb0217c Mon Sep 17 00:00:00 2001 From: Daniel Hunsaker Date: Fri, 22 Feb 2013 19:17:56 -0700 Subject: Updated exit codes as constant values Re-allocated exit status codes according to three references, which follow: BSD sysexits.h:http://www.gsp.com/cgi-bin/man.cgi?section=3&topic=sysexits GNU recomendations:http://www.gnu.org/software/libc/manual/html_node/Exit-Status.html Bash scripting:http://tldp.org/LDP/abs/html/exitcodes.html The GNU recommendations stem from and expand upon the standard C/C++ library (stdlibc) definitions, while also suggesting some best-practice conventions which happen to prevent exit status code collisions with bash, and probably other shells. The re-allocated codes are now mapped to constant values, set in *application/config/constants.php*, and used throughout the CodeIgniter core. They would additionally be used in *index.php*, but the constants file hasn't been loaded at that point, so the integer values are used instead, and a comment follows each such use with amplifying information on why that particular value was selected. Finally, the errors documentation has been updated accordingly. Signed-off-by: Daniel Hunsaker --- user_guide_src/source/general/errors.rst | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'user_guide_src/source/general') diff --git a/user_guide_src/source/general/errors.rst b/user_guide_src/source/general/errors.rst index 8c941aadb..1d6f8120d 100644 --- a/user_guide_src/source/general/errors.rst +++ b/user_guide_src/source/general/errors.rst @@ -18,6 +18,15 @@ procedural interfaces that are available globally throughout the application. This approach permits error messages to get triggered without having to worry about class/function scoping. +CodeIgniter also returns a status code whenever a portion of the core +calls ``exit()``. This exit status code is separate from the HTTP status +code, and serves as a notice to other processes that may be watching of +whether the script completed successfully, or if not, what kind of +problem it encountered that caused it to abort. These values are +defined in *application/config/constants.php*. While exit status codes +are most useful in CLI settings, returning the proper code helps server +software keep track of your scripts and the health of your application. + The following functions let you generate errors: show_error() @@ -36,7 +45,12 @@ following error template:: application/errors/error_general.php The optional parameter ``$status_code`` determines what HTTP status -code should be sent with the error. +code should be sent with the error. If ``$status_code`` is less than 100, +the HTTP status code will be set to 500, and the exit status code will +be set to ``$status_code + EXIT__AUTO_MIN``. If that value is larger than +``EXIT__AUTO_MAX``, or if ``$status_code`` is 100 or higher, the exit +status code will be set to ``EXIT_FAILURE``. You can check in +*application/config/constants.php* for more detail. show_404() ========== @@ -53,8 +67,9 @@ the following error template:: application/errors/error_404.php The function expects the string passed to it to be the file path to the -page that isn't found. Note that CodeIgniter automatically shows 404 -messages if controllers are not found. +page that isn't found. The exit status code will be set to ``EXIT_UNK_FILE``. +Note that CodeIgniter automatically shows 404 messages if controllers are +not found. CodeIgniter automatically logs any ``show_404()`` calls. Setting the optional second parameter to FALSE will skip logging. -- cgit v1.2.3-24-g4f1b