ruby-web and trapping errors

I

ivan.pavlov

I am using ruby-web to create a simple web application. Basically I
have some code, I process submitted forms and then I do

Web::eek:pen do
puts html
end

If an error occurs in the code I get : Internal Server Error in the
browser and no information whatsoever about the error.

My question is - can I make the exact error appear in the browser, so I
can fix it easily? I can run my code in console and then I see the
error but if I have user-submitted data before the error occured it
becomes difficult...
 
I

ivan.pavlov

Oops, this was stupid question - I found the answer myself.

begin
# code code code
rescue Exception => detail
Web::eek:pen do
puts detail.backtrace.join('<br>')
puts detail.to_s
end
end
 
P

patsplat

This is the main reason ruby-web provides a 'web-aware' interpreter.
There are certain types of errors that Web::eek:pen can't catch,
especially the dreaded "syntax error".

If you use the ruby-web interpreter, it will output cgi headers, plus
the Web::eek:pen block is not needed:

#!/usr/bin/ruby-web

....
puts html

This will catch the error and display to the browser. The cgi
interpreter works on Windows and Unix platforms, with fastcgi support
in linux if you installed the fcgi libraries. There are also ruby-web
handers for ModRuby which provide the same support. All the gory
details are at:

http://ruby-web.org/manual/install.html

Thanks for trying it out!

Cheers,

Patrick
 
I

ivan.pavlov

Patrick, thanks for the pointer to #!/usr/bin/ruby-web , I missed this
during the installation. Well, I guess I missed all the install
instructions.

I am very new to Ruby and am just exploring different things. Rails is
far too much for my needs and I found ruby-web does exactly what I
want. I probably use like 1% of its capabilities, because all I really
need are the data submitted by the user, once I have them, all the
program flow goes through various classes which in the end return a
string cotaining the whole HTML of the page. All the logic is in the
classes and I do not need to output anything piece by piece. So, in the
end I have a string which I pass to a single Web::eek:pen block and I'm
done.

I am using templates of course; having programmed in PHP for several
years I hate plain HTML in my code, so I took probably the worse
approach - wrote a small template engine myself, for reasons described
below.

In the end, I have to say I'm beginning to like Ruby. Code is shorter
than PHP and more elegant, which does not necessarily mean it takes
less time to write but sometimes it does. My only frustration is the
lack of good documentation for the external libraries I download from
rubyforge. Most people seem to think that a hastily prepared rdoc is
enough, and that examples are not really necessary because the user has
like 5 years of Ruby experience and understatnds everything just by
looking at a method name. I am not speaking here about the core classes
and methods which are indeed very well-documented.

I know that writing documentation is a pain. But this can really speed
up adoption of the language. Good, working examlpes of something
meaningful are the best documentation.


p.s. Patrick, this entry is in no way connected to ruby-web, I got
frustrated over some other libraries, like rexml.
 

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

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top