On 28 Dec 2003, Jesper Olsen wrote:

> Date: 28 Dec 2003 23:41:56 -0800
> From: Jesper Olsen <jolsen / mail2world.com>
> Newsgroups: comp.lang.ruby
> Subject: Re: system()
<snip>
> Rather a of problem the cgi-process not having permission to create files in
> that particular dir - so in this case also a "pure" ruby script would have
> failed (- but at least it would have produced an exception).
</snip>

a very helpful thing with any cgi program (mod_ruby, fastcgi, cgi, etc) is to
something _similar_ to this:

  #!/usr/bin/ruby
  require 'cgi'

  cgi     = CGI.new
  content = nil
  type    = nil

  begin
    ...
    # content << t.expand data
    ...
    # cgi stuff that can throw exceptions
    ...

  rescue Exception => e
    type = 'text/plain'
    content = <<-html
      #{ e }
      #{ e.backtrace.join "\n" }
    html

  ensure
    cgi.out('type' => type || 'text/html') { content }
  end


you get the idea - you can even do this only when running in non-interactive
mode (STDIN.tty? #=> false)

saves TONS of debugging time.  when code goes into production you can change
the message to a simply error message but mail yourself/log the backtrace.

-a
-- 

ATTN: please update your address books with address below!

===============================================================================
| EMAIL   :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE   :: 303.497.6469
| ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
| STP     :: http://www.ngdc.noaa.gov/stp/
| NGDC    :: http://www.ngdc.noaa.gov/
| NESDIS  :: http://www.nesdis.noaa.gov/
| NOAA    :: http://www.noaa.gov/
| US DOC  :: http://www.commerce.gov/
|
| The difference between art and science is that science is what we
| understand well enough to explain to a computer.  
| Art is everything else.  
|   -- Donald Knuth, "Discover"
|
| /bin/sh -c 'for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done' 
===============================================================================