How to catch error in array index when debugging

I'm getting a runtime failure "Error in array index". This causes ghci to exit. Is there a way to get it to break instead, so I can find out which function is failing? -- Colin Adams Preston Lancashire

Hello Colin, Saturday, March 14, 2009, 11:39:41 AM, you wrote:
I'm getting a runtime failure "Error in array index". This causes ghci to exit.
Is there a way to get it to break instead, so I can find out which function is failing?
i recall two techniques - one is trivially define your own (!) and print index at least. another is to use ghc profiling with -xc RTS option -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

I'm getting a runtime failure "Error in array index". This causes ghci to exit.
Is there a way to get it to break instead, so I can find out which function is failing?
i recall two techniques - one is trivially define your own (!) and print index at least. another is to use ghc profiling with -xc RTS option
None of which is satisfactory. You might also want to add yourself to this ticket: "index out of range" error message regression http://hackage.haskell.org/trac/ghc/ticket/2669 Claus

"Claus" == Claus Reinke
writes:
Claus> None of which is satisfactory. You might also want to add Claus> yourself to this ticket: Claus> "index out of range" error message regression Claus> http://hackage.haskell.org/trac/ghc/ticket/2669 How do I do that? -- Colin Adams Preston Lancashire

Claus> None of which is satisfactory. You might also want to add Claus> yourself to this ticket:
Claus> "index out of range" error message regression Claus> http://hackage.haskell.org/trac/ghc/ticket/2669
How do I do that?
Ghc Trac's idea of voting is by adding yourself to the cc, so that tickets can be sorted by length of cc list: http://hackage.haskell.org/trac/ghc/report/17 That is often subverted by closing tickets as duplicate/related, without transferring the cc list to the one ticket that is kept;-) Apart from the immediate bug of not getting any information, there's also the more general issue of wanting information about the call site (who called which operation, leading to the exception). A solution to that issue has been sought for a long time, but there seem to be so many options that the discussion has slowed down to a halt: Lexical call site string http://hackage.haskell.org/trac/ghc/ticket/960 Maintaining an explicit call stack http://hackage.haskell.org/trac/ghc/wiki/ExplicitCallStack Using your own wrappers to give you the missing information is probably the best short-term workaround, but it is no fun. Something like this, perhaps: import qualified Data.Array.IArray as A import Control.Exception arr ! index = mapException (addErrorInfo (" ! "++show index)) $ arr A.! index arr // idxs = mapException (addErrorInfo (" // "++show idxs)) $ arr A.// idxs addErrorInfo info (ErrorCall str) = ErrorCall (str++":"++info) test1 i = (A.array (1,5) [(i,i)|i<-[1..5]] :: A.Array Int Int) ! i test2 i = (A.array (1,5) [(i,i)|i<-[1..5]] :: A.Array Int Int) // [(i,0)] *Main> test1 0 *** Exception: Error in array index: ! 0 *Main> test1 3 3 *Main> test1 8 *** Exception: Error in array index: ! 8 *Main> test2 0 array *** Exception: Error in array index: // [(0,0)] *Main> test2 4 array (1,5) [(1,1),(2,2),(3,3),(4,0),(5,5)] *Main> test2 7 array *** Exception: Error in array index: // [(7,0)] Claus

"Claus" == Claus Reinke
writes:
Claus> None of which is satisfactory. You might also want to add Claus> yourself to this ticket: >> Claus> "index out of range" error message regression Claus> http://hackage.haskell.org/trac/ghc/ticket/2669 >> >> How do I do that? Claus> Ghc Trac's idea of voting is by adding yourself to the cc, Claus> so that tickets can be sorted by length of cc list: I was asking specifically how I add myself to the CC list. There is no button to do so. There is a CC text field, but last time I typed my name there, it ERASED the previous member of the CC list. Rather than a wrapper, I coded an assert, and added it in all the places where I used (!). That was no fun. It did identify the calling function, but that doesn't tell me anything very interesting. I now have to repeat the process for all the callers of that function, which is no joke. -- Colin Adams Preston Lancashire

You can use the ghci debugger
http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci- debugger.html
it can set breakpoints on exceptions. Am 14.03.2009 um 09:39 schrieb Colin Paul Adams:
I'm getting a runtime failure "Error in array index". This causes ghci to exit.
Is there a way to get it to break instead, so I can find out which function is failing? -- Colin Adams Preston Lancashire _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

"Adrian" == Adrian Neumann
writes:
Adrian> You can use the ghci debugger >> http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci- Adrian> debugger.html Adrian> it can set breakpoints on exceptions. So i tried adding the -fbreak-on-error flag. It made no difference - it still exited: <interactive>: Error in array index <interactive>: interrupted <interactive>: warning: too many hs_exit()s Adrian> Am 14.03.2009 um 09:39 schrieb Colin Paul Adams: >> I'm getting a runtime failure "Error in array index". This >> causes ghci to exit. >> >> Is there a way to get it to break instead, so I can find out >> which function is failing? -- Colin Adams Preston Lancashire -- Colin Adams Preston Lancashire

Colin Paul Adams wrote:
"Adrian" == Adrian Neumann
writes: Adrian> You can use the ghci debugger >> http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci- Adrian> debugger.html
Adrian> it can set breakpoints on exceptions.
So i tried adding the -fbreak-on-error flag. It made no difference - it still exited:
<interactive>: Error in array index <interactive>: interrupted <interactive>: warning: too many hs_exit()s
IIRC, this is because you are catching exceptions at some higher level where you actually find out that this kind of an exception is not handled and give up. If your application is Gtk2Hs then this library will do the catching you do not like in this case. Try to use -fbreak-on-exception instead of -fbreak-on-error. If you try this you may need to set break-on-exception late enough in the execution (use some breakpoint) so that you are not stopping at places which are ok (are correctly handled in an exception handler). In addition to other solutions mentioned here you can also setup conditional breakpoints in GHCi because GHCi breakpoints can be scripted. This is what I mostly use. Most of my debugging is done by writing GHCi debug scripts. Some ideas how to do it are here: http://permalink.gmane.org/gmane.comp.lang.haskell.glasgow.user/16270 It does not work well for interactive command line applications now, but it will work well for them when GHC 6.10.2 is out (the three most critical patches were merged). This alternative may have steep learning curve for such a simple thing but once mastered it works well. Peter.

"Peter" == Peter Hercek
writes:
Peter> Colin Paul Adams wrote:
>>>>>>> "Adrian" == Adrian Neumann
participants (5)
-
Adrian Neumann
-
Bulat Ziganshin
-
Claus Reinke
-
Colin Paul Adams
-
Peter Hercek