Error messages and CGI

Discussion in 'Ruby' started by Henrik Ronellenfitsch, Feb 8, 2005.

  1. 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, Feb 8, 2005
    #1
    1. Advertising

  2. Henrik Ronellenfitsch <> 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
     
    Matt Armstrong, Feb 8, 2005
    #2
    1. Advertising

  3. Henrik Ronellenfitsch

    Patrick May Guest

    Henrik,

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

    > 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
     
    Patrick May, Feb 10, 2005
    #3
  4. Thank you both very much
     
    Henrik Ronellenfitsch, Feb 10, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jürgen Exner

    Re: CGI Perl "use CGI" statement fail

    Jürgen Exner, Jul 31, 2003, in forum: Perl
    Replies:
    0
    Views:
    1,546
    Jürgen Exner
    Jul 31, 2003
  2. Stefan Fischer
    Replies:
    2
    Views:
    335
    Stefan Fischer
    Feb 23, 2010
  3. zippy

    cgi and cgi-bin

    zippy, Feb 1, 2005, in forum: Perl Misc
    Replies:
    5
    Views:
    426
    Sam Holden
    Feb 2, 2005
  4. Sam
    Replies:
    1
    Views:
    174
    A. Sinan Unur
    Feb 20, 2007
  5. PerlFAQ Server
    Replies:
    0
    Views:
    139
    PerlFAQ Server
    Apr 3, 2011
Loading...

Share This Page