Error messages and CGI

Hello,
is it possible to let ruby print error messages directly as text to the cgi-output, like the way php prints it's error messages?
It's kind of impractical to always have to check the apache error log.

Thanks,
Henrik

Henrik Ronellenfitsch <hen_WEG_damit_rik@searinox.de> writes:

Hello,
is it possible to let ruby print error messages directly as text to the
cgi-output, like the way php prints it's error messages?
It's kind of impractical to always have to check the apache error log.

Thanks,
Henrik

This approach will cause any exception in my main() function to be
printed out for the user to see. Syntax errors won't be caught, of
course, but even that can be handled by making the main .cgi script a
tiny wrapper with all the logic in a separate file that is loaded
within the begin...rescue...end. I stick my whole script in a timeout
block, since I've had odd problems cause a script to hang forever,
causing bad load on the HTTP server.

def exception_string(cgi, exception)
  s1 = cgi.h1{"Exception:"} +
    CGI::escapeHTML(exception.inspect) +
    cgi.h1{"Backtrace:"}
  s2 = ""
  exception.backtrace.each { |line|
    s2 = s2 + CGI::escapeHTML(line) + cgi.br
  }
  return s1 + s2
end

cgi = CGI::new('html4Tr')
begin
  timeout(60 * 10) {
    main(cgi)
  }
rescue Exception => exception
  cgi.out {
    cgi.html {
      cgi.head {
        cgi.title { "#{TITLE}: Exception" }
      } +
        cgi.body {
        exception_string(cgi, exception)
      }
    }
  }
end

···

--
matt

Henrik,

is it possible to let ruby print error messages directly as text to the cgi-output, like the way php prints it's error messages?
It's kind of impractical to always have to check the apache error log.

To do this properly, you need to make the ruby interpreter web-aware. This way you can catch SyntaxErrors. The development version of Narf has such an interpreter. What platform are you working on?

In a month or so, Narf will have a major release. If you can't wait and use subversion, you can check out narf at:

     http://svn.narf-lib.org/svn/narf/trunk/

Cheers,

Patrick

···

On Tuesday, February 8, 2005, at 11:00 AM, Henrik Ronellenfitsch wrote: