From: Brian Candler Date: 2004-10-07T22:37:55+09:00 Subject: Re: quality of error messages On Thu, Oct 07, 2004 at 10:08:59PM +0900, Gavin Sinclair wrote: > > class Foo > > def m1 > > if 1 == 2 > > puts "Bad" > > end > > raise unless Class === self # nothing happens > > end > > Try > > puts 'foo' > > then. If it's in a class, it will print it. If it's in a method, it > won't. Good enough for debugging? Hmm: puts "OK at #{__LINE__}" if Class === self Well, this statement won't be executed until the whole file has been successfully parsed first. So if you take an example like this: ---- 8< ---- #!/usr/local/bin/ruby -w def checkpoint(x) puts "OK(#{x}) at #{caller[0]}" end checkpoint(:Foo) class Foo checkpoint(:bar) def bar(x) if x == 3 puts "hello" end checkpoint(:baz) def baz(y) end checkpoint("end of Foo") end ---- 8< ---- $ ruby ert.rb ert.rb:18: syntax error Then you have to keep adding 'end' statements until it parses successfully. You then get: OK(Foo) at ert.rb:7 OK(bar) at ert.rb:9 at which point you can cross-reference to each of the checkpoint lines in the code, until you find which checkpoint(s) are missing from the output. I guess it's feasible... but it would be much better if it could work the other way round, and show you were the error was, not where the good lines were :-) Cheers, Brian.