Rescuing errors.. catch-all

Hi,

Im trying to print all error information to the browser so I don’t have
to monitor the apache log every time I have a syntax error.

So far, it’s working very well with

begin

main prg

rescue SystemCallError => rescueError
if (rescueError)
puts "

"
puts rescueError.message
puts rescueError.backtrace
puts "
"
end
end

however, I have to specify the error, is there some sort of catch-all
exception I can use? I tried ‘Exception’ which catches SystemCallErrors
as far as I could tell, but I still got Internal Errors (500)

db

···


Jun 19* Corpus Christi (11 days after Pentecost)
Jun 19 Julius and Ethel Rosenberg are executed in Sing-Sing prison, 1953
Jun 19 Lizzie Bordon acquitted, 1893
Jun 19 Emancipation Day in Texas
Jun 19 Labor Day in Trinidad and Tobago
Jun 19 Revolution Day in Algeria
Jun 19 Artigas Birthday in Uruguay

Hi,

Im trying to print all error information to the browser so I don’t have
to monitor the apache log every time I have a syntax error.

So far, it’s working very well with

begin

main prg

rescue SystemCallError => rescueError
if (rescueError)
puts “


puts rescueError.message
puts rescueError.backtrace
puts “

end
end

however, I have to specify the error, is there some sort of catch-all
exception I can use? I tried ‘Exception’ which catches SystemCallErrors
as far as I could tell, but I still got Internal Errors (500)

i think this is good as you can get - Exception is the mother of them all. if
you are getting other (500) errors it means your script is not running
(permissions, etc.), so it’s pretty tough for ruby to catch/report errors.
:wink:

you can configure apache to do different things for this but that’s way OT…

cheers.

-a

db


Jun 19* Corpus Christi (11 days after Pentecost)
Jun 19 Julius and Ethel Rosenberg are executed in Sing-Sing prison, 1953
Jun 19 Lizzie Bordon acquitted, 1893
Jun 19 Emancipation Day in Texas
Jun 19 Labor Day in Trinidad and Tobago
Jun 19 Revolution Day in Algeria
Jun 19 Artigas Birthday in Uruguay

-a

···

On Fri, 20 Jun 2003, Daniel Bretoi wrote:

====================================

Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ara.t.howard@noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
~ > ruby -e ‘p(%.\x2d\x29…intern)’
====================================

Hi,

···

In message “rescuing errors… catch-all” on 03/06/20, Daniel Bretoi lists@debonair.net writes:

however, I have to specify the error, is there some sort of catch-all
exception I can use? I tried ‘Exception’ which catches SystemCallErrors
as far as I could tell, but I still got Internal Errors (500)

Exception should catch all errors. But rescue does not help, when you
get error before entering protected region (main, this case), for
example, syntax errors, or even in kicking interpreter.

						matz.

One day i wrote special addition to Exception class, so it outputs quite
pretty exception information to the browser window, it’s attached.
When it’s included u can just do this:

begin
#code here
rescue Exception => e # not sure about this, i always had rescue => e here
e.backtrace_html if e.methods.include? ‘backtrace_html’
end

All backtracing code is made by ‘in-place html’ couse i wanted it to be
totally independent from any template engines and so on.

Maybe it will be usefull to you.

errors.rb (2.14 KB)

···

On Friday 20 June 2003 08:04, Daniel Bretoi wrote:

Hi,

Im trying to print all error information to the browser so I don’t have
to monitor the apache log every time I have a syntax error.


sdmitry -=- Dmitry V. Sabanin
MuraveyLabs.

would this seem to be a reasonable feature request to make? it would be
very nice to be able to catch everything and be able to do with it what
you like, especially with html.

···

On Fri, Jun 20, 2003 at 09:56:04AM +0900, Yukihiro Matsumoto wrote:

Hi,

In message “rescuing errors… catch-all” > on 03/06/20, Daniel Bretoi lists@debonair.net writes:

however, I have to specify the error, is there some sort of catch-all
exception I can use? I tried ‘Exception’ which catches SystemCallErrors
as far as I could tell, but I still got Internal Errors (500)

Exception should catch all errors. But rescue does not help, when you
get error before entering protected region (main, this case), for
example, syntax errors, or even in kicking interpreter.

thanks, I’ll have a look at it :slight_smile:

db

···

On Fri, Jun 20, 2003 at 08:10:40PM +0900, Dmitry V. Sabanin wrote:

On Friday 20 June 2003 08:04, Daniel Bretoi wrote:

Hi,

Im trying to print all error information to the browser so I don’t have
to monitor the apache log every time I have a syntax error.

One day i wrote special addition to Exception class, so it outputs quite
pretty exception information to the browser window, it’s attached.
When it’s included u can just do this:

begin
#code here
rescue Exception => e # not sure about this, i always had rescue => e here
e.backtrace_html if e.methods.include? ‘backtrace_html’
end

All backtracing code is made by ‘in-place html’ couse i wanted it to be
totally independent from any template engines and so on.

Maybe it will be usefull to you.


sdmitry -=- Dmitry V. Sabanin
MuraveyLabs.

class Exception def backtrace_html line_color = ‘white’ lineHead_color
= ‘#FDDFA0’ error_color = ‘red’ special_color = ‘blue’ adminMail =
‘dmitry@iren.info’ odd_color = ‘F2E8B3’ even_color = ‘F5E693’ errsect
= to_s.scan (/^([\w\s]*)[|]{3}/) if errsect.length > 0 errtext =
to_s.scan(/[|]{3}(.)$/) errtext = errtext.join(‘’) else errtext =
to_s errsect = ‘Unexpected’ end print "

 Ruby Error Report (Version #{VERSION}, platform #{RUBY_PLATFORM})

                         #{errsect} error:
          There was an error while perfoming your request:
                    #{CGI.escapeHTML(errtext)} 
                    Exception type #{type.to_s}

File Name Line Number Method Name " colorifier = 0 backtrace.each do

line> fileName, lineNum, methodName = line.split(/:/) if
line.scan(/\d*:in/).length > 0 methodName = *methodName.scan(/\w*'/) methodName.gsub!(/[‘]/,’') if methodName end if
colorifier.divmod(2)[1] == 0 row_color = odd_color else row_color =
even_color end print "
#{fileName} #{lineNum} #{methodName if defined? methodName}
" colorifier += 1 end print "
If you wish to help us, please e-mail our [1]administrator about this
error…
This report was generated at #{Time.now}.
" end end

References

  1. mailto:/#{adminMail}


Jun 22 Carl Hubbell born, 1903
Jun 22 Meryl Streep born in Summit, New Jersey, 1949
Jun 20 Victoria crowned, 1837
Jun 21 Berlin airlift begins, 1948
Jun 21 Sun rises over Heelstone at Stonehenge
Jun 22 Civil rights workers disappear in Mississippi, 1964
Jun 20 Flag Day in Argentina
Jun 20 West Virginia Day in West Virginia
Jun 22 National Sovereignty Day in Haiti
Jun 22 Corrective Movement in Yemen Democratic Republic
Jun 22 Midsummer Eve in Finland, Sweden
Jun 21 Columbia records announces the first mass production of LP’s, 1948
Jun 22 Todd Rundgren is born in Upper Darby, Pennsylvania, 1948
Jun 21* Summer Solstice
Jun 22* Parashat Balak
Jun 22* Parashat Hukkat

this is easy to do for yourself:

~ > cat index.cgi # wrap your cgi’s in a baby shell script which dups 2 as 1
#!/bin/sh
cgi=‘foo.rb’
$cgi 2>&1

~ > cat foo.rb # any output from program - even from ruby failing - sent to browser
#!/usr/local/bin/ruby
<<| doesn’t even parse |>>

~ > ./index.cgi > out; cat out # note that all errors went to stdout - e.g. displayed by browser
…/foo.rb:2: parse error
<<| doesn’t even parse |>>
^
…/foo.rb:2: unterminated string meets end of file

when index.cgi is run all output, including errors, are displayed.

-a

···

On Sat, 21 Jun 2003, Daniel Bretoi wrote:

would this seem to be a reasonable feature request to make? it would be very
nice to be able to catch everything and be able to do with it what you like,
especially with html.

Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ara.t.howard@noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
~ > ruby -e ‘p(%.\x2d\x29…intern)’
====================================

Hi,

···

In message “Re: rescuing errors… catch-all” on 03/06/21, Daniel Bretoi lists@debonair.net writes:

Exception should catch all errors. But rescue does not help, when you
get error before entering protected region (main, this case), for
example, syntax errors, or even in kicking interpreter.

would this seem to be a reasonable feature request to make? it would be
very nice to be able to catch everything and be able to do with it what
you like, especially with html.

I’m afraid that your request is rb_protect() to catch everything.
Unfortunately it’s impossible.

						matz.

would this seem to be a reasonable feature request to make? it would be very
nice to be able to catch everything and be able to do with it what you like,
especially with html.

this is easy to do for yourself:

perhaps with cgi, but I’m using embedded ruby. And I was thinking if
it could be a benefit in other areas to be able to redirect errors like
that…

db

···

On Sat, Jun 21, 2003 at 02:16:18AM +0900, ahoward wrote:

On Sat, 21 Jun 2003, Daniel Bretoi wrote:

~ > cat index.cgi # wrap your cgi’s in a baby shell script which dups 2 as 1
#!/bin/sh
cgi=‘foo.rb’
$cgi 2>&1

~ > cat foo.rb # any output from program - even from ruby failing - sent to browser
#!/usr/local/bin/ruby
<<| doesn’t even parse |>>

~ > ./index.cgi > out; cat out # note that all errors went to stdout - e.g. displayed by browser
…/foo.rb:2: parse error
<<| doesn’t even parse |>>
^
…/foo.rb:2: unterminated string meets end of file

when index.cgi is run all output, including errors, are displayed.

-a

====================================

Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ara.t.howard@noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
~ > ruby -e ‘p(%.\x2d\x29…intern)’
====================================


Jun 22 Carl Hubbell born, 1903
Jun 22 Meryl Streep born in Summit, New Jersey, 1949
Jun 20 Victoria crowned, 1837
Jun 21 Berlin airlift begins, 1948
Jun 21 Sun rises over Heelstone at Stonehenge
Jun 22 Civil rights workers disappear in Mississippi, 1964
Jun 20 Flag Day in Argentina
Jun 20 West Virginia Day in West Virginia
Jun 22 National Sovereignty Day in Haiti
Jun 22 Corrective Movement in Yemen Democratic Republic
Jun 22 Midsummer Eve in Finland, Sweden
Jun 21 Columbia records announces the first mass production of LP’s, 1948
Jun 22 Todd Rundgren is born in Upper Darby, Pennsylvania, 1948
Jun 21* Summer Solstice
Jun 22* Parashat Balak
Jun 22* Parashat Hukkat

Could there be another form of load that would report parse errors as an
exception instead of crashing the entire process?

begin
load_with_precaution(‘junk.pl’)
rescue
puts “Cannot load that piece of !@#$”
end

Guillaume.

···

On Fri, 2003-06-20 at 14:29, Yukihiro Matsumoto wrote:

Hi,

In message “Re: rescuing errors… catch-all” > on 03/06/21, Daniel Bretoi lists@debonair.net writes:

Exception should catch all errors. But rescue does not help, when you
get error before entering protected region (main, this case), for
example, syntax errors, or even in kicking interpreter.

would this seem to be a reasonable feature request to make? it would be
very nice to be able to catch everything and be able to do with it what
you like, especially with html.

I’m afraid that your request is rb_protect() to catch everything.
Unfortunately it’s impossible.

  					matz.

Hi,

Could there be another form of load that would report parse errors as an
exception instead of crashing the entire process?

begin
load_with_precaution(‘junk.pl’)
rescue
puts “Cannot load that piece of !@#$”
end

begin
load(‘junk.pl’)
rescue SyntaxError
puts “Cannot load that piece of !@#$”
end

should work.

						matz.
···

In message “Re: rescuing errors… catch-all” on 03/06/21, Guillaume Marcais guslist@free.fr writes:

Oops, my mistake. It does work. I though, after a quick test, that it
didn’t. Cool!

Guillaume.

···

Le samedi, 21 jun 2003, à 00:33 US/Eastern, Yukihiro Matsumoto a écrit :

Hi,

In message “Re: rescuing errors… catch-all” > on 03/06/21, Guillaume Marcais guslist@free.fr writes:

Could there be another form of load that would report parse errors as
an
exception instead of crashing the entire process?

begin
load_with_precaution(‘junk.pl’)
rescue
puts “Cannot load that piece of !@#$”
end

begin
load(‘junk.pl’)
rescue SyntaxError
puts “Cannot load that piece of !@#$”
end

should work.

  					matz.