Rescue don't work on web applications

Hi,

I’ve a Rails application who starts a Ruby script .
The script is made via Web -> database.
Than you can select a script to start via a database list.

Problem:

In case of errors , I like to start a rescue showing the users the
problems.

render(:text => “

” + CGI::escapeHTML(`
begin
/home/luc/radrails/cpe/public/startq_test.rb #{syntf.path}
rescue
NoMethodError,SyntaxError,NameError,StandardError,SystemExit,ScriptError
=> snfault
fltlog = File.open("/test/result/script.log", “w”)
fltlog.puts “#{snfault}”
fltlog.close
end
    `) + "</pre>")

Rescue don’t work in this case, how can I check syntax errors?

On 11/2/06, lucevers [email protected] wrote:

problems.
fltlog.close
end

    `) + "</pre>")

Rescue don’t work in this case, how can I check syntax errors?

You are using the backtick operator improperly. Basically, you are
doing this:

render(:text => “

” + CGI::escapeHTML(IO.popen("
begin
/home/luc/radrails/cpe/public/startq_test.rb #{syntf.path}
rescue
NoMethodError,SyntaxError,NameError,StandardError,SystemExit,ScriptError
=> snfault
fltlog = File.open("/test/result/script.log", “w”)
fltlog.puts “#{snfault}”
fltlog.close
end
     ").read) + "</pre>")

which executes your shell with “begin
/home/luc/radrails/cpe/public/startq_test.rb …”. Since you are
trying to execute ruby code in the shell, you lose.

Something like this may work, though:

render(:text => “

” + CGI::escapeHTML(eval("
begin
/home/luc/radrails/cpe/public/startq_test.rb #{syntf.path}
rescue
NoMethodError,SyntaxError,NameError,StandardError,SystemExit,ScriptError
=> snfault
fltlog = File.open("/test/result/script.log", “w”)
fltlog.puts “#{snfault}”
fltlog.close
end
     ")) + "</pre>")

Make sure you check the values of syntf.path and snfault carefully
before doing that.

Jeremy

Jeremy

Thanks for your solution I’ll test this.
But I also did a lot of other checks:

If you start via cli a Ruby script with the next info:

begin
eval("#{fquery}")
rescue SyntaxError,NameError,StandardError => snfault
fltlog.puts “#{snfault}” -> put result in a file
end


Method: In case of a bug via rescue a log file has all the information.

When you put a syntax fault in fquery: example -> pust “test” (puts)
everything works in CLI.
You get the log file.
But if you start the same script via a Ruby on Rails controller you
don’t
get de result = log file.
I did several tests and I’m sure that ‘rescue’ don’t work via ruby on
Rails
controller. (starting an external script)
Is it a bug ?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs