Arc Forumnew | comments | leaders | submitlogin
How to see a full traceback in anarki?
5 points by svetlyak40wt 3959 days ago | 3 comments
If there a way to see full traceback instead just: `Error: "car: contract violation\n expected: pair?\n given: #<procedure: queue*>"`?


4 points by rocketnia 3958 days ago | link

I took a look at http://docs.racket-lang.org/reference/exns.html and found something that works.

Look for these lines in ac.scm:

                (display "Error: ")
                (write (exn-message c))
Replace them with this:

                ((error-display-handler) (exn-message c) c)
Before:

  arc> (+ 1 (fn))
  Error: "cadr: contract violation\n  expected: (cons/c any/c pair?)\n  given: '(fn)"
  arc> (def foo () (map [+ 1 (fn ())] list.nil))
  #<procedure: foo>
  arc> (foo)
  Error: "+: contract violation\n  expected: number?\n  given: #<procedure: foo>\n  argument position: 2nd\n  other arguments...:\n   1"
After:

  arc> (+ 1 (fn))
  cadr: contract violation
    expected: (cons/c any/c pair?)
    given: '(fn)
    context...:
     C:\mine\prog\repo\anarki\ac.scm:24:22: ac
     C:\Program Files (x86)\Racket\collects\racket\private\map.rkt:26:19: loop
     C:\mine\prog\repo\anarki\ac.scm:486:0: ac-call
     C:\mine\prog\repo\anarki\ac.scm:1218:4
  
  arc> (def foo () (map [+ 1 (fn ())] list.nil))
  #<procedure: foo>
  arc> (foo)
  +: contract violation
    expected: number?
    given: #<procedure: foo>
    argument position: 2nd
    other arguments...:
     1
    context...:
      map1
     C:\mine\prog\repo\anarki\ac.scm:1218:4
In these examples, the first error happens during macroexpansion, when the compiler is processing the 'fn special form. The second error happens at run time. They both recover to the REPL just fine.

The second stack trace doesn't include 'foo or 'map, but I bet that's because they made a call in tail position, leaving no trace of their stack frame. Let's change 'foo so it doesn't do that:

  arc> (def foo () (map [+ 1 (fn ())] list.nil) nil)
  *** redefining foo
  #<procedure: foo>
  arc> (foo)
  +: contract violation
    expected: number?
    given: #<procedure: foo>
    argument position: 2nd
    other arguments...:
     1
    context...:
      map1
      foo
     C:\mine\prog\repo\anarki\ac.scm:1218:4
Yep, looking good. :)

Arc seems to throw away source location information, but I think we could get that back too if we tried. It'll involve using Racket syntax objects somehow.

Thanks for speaking up about this. This seems like something that could help a lot of people. XD

-----

2 points by svetlyak40wt 3957 days ago | link

Wow, this is very helpful even without source locations!

-----

2 points by akkartik 3957 days ago | link

Indeed, this is wonderful. I've updated anarki.

-----