Arc Forumnew | comments | leaders | submitlogin
4 points by rocketnia 3923 days ago | link | parent

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 3922 days ago | link

Wow, this is very helpful even without source locations!

-----

2 points by akkartik 3922 days ago | link

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

-----