debugging a cgi

M

mark

Hi,
Is there a good way to get more information about what went wrong in a
ruby cgi script than just a 500 error page?
I know I could run it from a shell but this isn't always an option.
I'm running as cgi on apache.
Thanks,
- Mark
 
H

Harold Hausman

So far, what I've found is that it's pretty much all about running it
from the shell. It will be recognized by the interpreter as a cgi
script and you will be prompted for name=3Dvalue pairs for the query
string. Works supprisingly well.

Of course, if theres something better I'd love to know too.

-Harold
 
D

Detlef Reichl

Hi,
Is there a good way to get more information about what went wrong in a
ruby cgi script than just a 500 error page?

Ehm...

take a look to the webserver logs?

/var/log/apache(2)/error.log

Cheers
detlef
 
M

mark

Thanks for the suggestions, however running from the shell and viewing
logs are not usually available in budget hosting packages. I found a
way to do what I want with mod_ruby by setting up a custom 500 page and
putting:

r = Apache.request
rp = r.prev
backtrace_id = nil
puts rp.error_message.to_s

however this only works for mod_ruby.
Any tips much appreciated
 
B

Bob Showalter

mark said:
Thanks for the suggestions, however running from the shell and viewing
logs are not usually available in budget hosting packages.

I'm not an expert on this, but why not wrap your entire script in
something like this:

begin

...your script here...

rescue Exception
print "Content-Type: text/plain\r\n\r\n"
puts $!.inspect, $!.backtrace
end

That should put out a valid response for any uncaught exception and show
the error at the client.
 
M

mark

Thanks for the suggestion,
but this will only help in cases where an Exception is thrown.
 
B

Bob Showalter

mark said:
Thanks for the suggestion,
but this will only help in cases where an Exception is thrown.

What could cause a 500 response?

1) Script won't pass 'ruby -c'. You can check this on another system.
2) Script emits a malformed MIME header. This should be easy to check.
3) Script raises an exception.

Is there something else I'm not seeing?
 
M

mark

Hi Bob,
The idea is to make debugging cgi's easier. Yes I can check it on
another system, but it's a hassle.

In addition to your suggestion here's what I came up with so far:
I made a custom 500 error document called /500.rb and put:
----------------
#!/usr/local/bin/ruby
print "Content-Type: text/plain\n\n"
unless ENV["REQUEST_URI"] == "/500.rb" # to avoid recursion
script = ENV["DOCUMENT_ROOT"] + ENV["REQUEST_URI"]
puts `/usr/local/bin/ruby #{script} 2>&1`
end
----------------
this doesn't deal with the get and post vars but I'll fix that later.
It would be nice if there is a way to get ruby to bomb to the 500 page
on exceptions so that I don't need the 'rescue' on every page. right
now the exception just causes ruby to quit without going to the 500
page

Thanks for the input,
- Mark
 

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
474,197
Messages
2,571,040
Members
47,635
Latest member
SkyePurves

Latest Threads

Top