Error messages and CGI

  • Thread starter Henrik Ronellenfitsch
  • Start date
H

Henrik Ronellenfitsch

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
 
M

Matt Armstrong

Henrik Ronellenfitsch said:
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
 
P

Patrick May

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top