REBOL [
Title: "CGI wrapper function for debugging"
Date: 12-jul-2003
Version: 0.0.1
File: %cgi-debug.r
Author: "Sunanda"
Purpose: "Provides debugging info for scripts running as a CGI under a webserver"
library: [
level: 'beginner
platform: 'all
type: [function tool]
domain: [cgi web]
tested-under: [win unix linux]
support: none
license: bsd
see-also: none
]
]
cgi-debug: func [target-code [block!]
/silent
/local
cgi-debug-capture-error
ip-address
][
;; == Usage:
;; == cgi-debug [block of code]
;;
;; == With a bit of luck, wrapping this round a
;; == block of code will return a html page with
;; == the error details, if it goes wrong.
;; ==
;; == That html may be appended to to html you've
;; == emitted prior to the failure, so it might
;; == look a mess.
if error? cgi-debug-capture-error: try [do target-code 1]
[
if not silent
[
print "Content-type: text/html^/"
print
print
print form now/precise
print "
Sorry, we've had an unexpected error"
print ["
=====Error in script" system/options/script "=====
"]
print
print