Debug.rb and exceptions


(Han Holl) #1

Hi,

I’m trying to debug a program that uses ftools.rb to rename (mv)
a file, and I get the following:

/usr/lib/ruby/1.6/ftools.rb:71: Invalid cross-device link - "/tmp/functies.20443.rb"' (Errno::EXDEV) from /usr/lib/ruby/1.6/ftools.rb:71:inmove’
from trans3.rb:577:in `main’
from trans3.rb:589
/usr/lib/ruby/1.6/ftools.rb:71: rename from, to

I look at ftools.rb, and see that it does something like:

begin
  rename from, to
rescue
  begin
    symlink File.readlink(from), to and unlink from

Because I want to mv a file between filesystems, the rename raises an
exception, which the debugger catches.
Question: how can I avoid this. I haven’t seen anything in the debug.rb
documentation (?) on this issue. It should be fairly common, I would
suspect.

Cheers,

Han Holl


(Ned Konz) #2

Easy: catch the Errno::EXDEV and instead do a copy followed by a
delete of the original.

···

On Monday 17 June 2002 02:04 pm, Han Holl wrote:

Because I want to mv a file between filesystems, the rename raises
an exception, which the debugger catches.
Question: how can I avoid this. I haven’t seen anything in the
debug.rb documentation (?) on this issue. It should be fairly
common, I would suspect.


Ned Konz
http://bike-nomad.com
GPG key ID: BEEA7EFE


(Han Holl) #3

Ned Konz wrote:

···

On Monday 17 June 2002 02:04 pm, Han Holl wrote:

Because I want to mv a file between filesystems, the rename raises
an exception, which the debugger catches.
Question: how can I avoid this. I haven’t seen anything in the
debug.rb documentation (?) on this issue. It should be fairly
common, I would suspect.

Easy: catch the Errno::EXDEV and instead do a copy followed by a
delete of the original.

That is not what I meant at all. What you propose is exactly what ftools.rb
does. My question: is it impossible to use the debugger with software that
uses begin - rescue in Python style ?

Han


(Ned Konz) #4

Sorry, I misunderstood.

trace_func, you’ll see that ‘raise’ conditions are handled by
excn_handle(), which does nothing (other than printing a trace to
stdout) if you don’t have a catchpoint set.

Of course, you have to get rid of the default catchpoint on
StandardError if you want to ignore any of these.

So if you start up the debugger with (say)

cat SystemExit

then it won’t break for any exception other than one that’s derived
from SystemExit. You could define your own exception if you wanted to
really make sure that you didn’t catch anything.

Here’s an example program (which I called xx.rb):

begin
puts "before"
raise StandardError
puts "after"
rescue StandardError
puts "caught"
end

And here’s my debug session:

$ ruby -rdebug xx.rb
Debug.rb
Emacs support available.

xx.rb:8:end
(rdb:1) cat SystemExit
Set catchpoint SystemExit.
(rdb:1) c
before
xx.rb:4: `StandardError’ (StandardError)
caught

···

On Tuesday 18 June 2002 11:00 am, Han Holl wrote:

Ned Konz wrote:

Easy: catch the Errno::EXDEV and instead do a copy followed by a
delete of the original.

That is not what I meant at all. What you propose is exactly what
ftools.rb does. My question: is it impossible to use the debugger
with software that uses begin - rescue in Python style ?

From my reading of debug.rb, it should be possible. If you look at the

Ned Konz
http://bike-nomad.com
GPG key ID: BEEA7EFE


(Han Holl) #5

Ned Konz wrote:

···

On Tuesday 18 June 2002 11:00 am, Han Holl wrote:

Ned Konz wrote:

Easy: catch the Errno::EXDEV and instead do a copy followed by a
delete of the original.

That is not what I meant at all. What you propose is exactly what
ftools.rb does. My question: is it impossible to use the debugger
with software that uses begin - rescue in Python style ?

Sorry, I misunderstood.

From my reading of debug.rb, it should be possible. If you look at the
trace_func, you’ll see that ‘raise’ conditions are handled by
excn_handle(), which does nothing (other than printing a trace to
stdout) if you don’t have a catchpoint set.

Of course, you have to get rid of the default catchpoint on
StandardError if you want to ignore any of these.

So if you start up the debugger with (say)

cat SystemExit

then it won’t break for any exception other than one that’s derived
from SystemExit. You could define your own exception if you wanted to
really make sure that you didn’t catch anything.

Here’s an example program (which I called xx.rb):

begin
puts "before"
raise StandardError
puts "after"
rescue StandardError
puts "caught"
end

And here’s my debug session:

$ ruby -rdebug xx.rb
Debug.rb
Emacs support available.

xx.rb:8:end
(rdb:1) cat SystemExit
Set catchpoint SystemExit.
(rdb:1) c
before
xx.rb:4: `StandardError’ (StandardError)
caught

Yes, this works. You get a lot of disconcerting error messages, but
it does indeed work.
I guess I didn’t quite get what a catchpoint is.
Documentation on debug.rb is scarce indeed.

Thanks for your help,

Han