[racket] Confusing blame message

From: Daniel Prager (daniel.a.prager at gmail.com)
Date: Mon Sep 2 16:57:56 EDT 2013

Hi Matthias

Thanks for the explanation - it helps.  I played with the kind of
post-condition "broken contract" example that you gave, and find it less
problematic, since the blame is local to the function / supplier.

If the error in my original example was reformatted by moving the at clause
to the top (easy?) and supplemented with the line number of the guilty
client [or supplier] code (hard?) I think it would reduce the confusion and
improve the utility.  I.e.

twice: contract violation
     at: .../blame-test.rkt - line 2, column 18
     expected: number?
     given: 'foo
     in: the 1st argument of
          (-> number? number?)
     contract from: (function twice)
     blaming: .../blame-test.rkt - line 6, column 1


What do you think?


Kind regards

Dan


On Mon, Sep 2, 2013 at 11:48 PM, Matthias Felleisen <matthias at ccs.neu.edu>wrote:

>
> On Sep 2, 2013, at 8:22 AM, Daniel Prager wrote:
>
> Consider this file:
>
> --------------------------------------------
> #lang racket
> (define/contract (twice x)
>   (-> number? number?)
>   (* 2 x))
>
> (twice 'foo)
> --------------------------------------------
>
> When run in DrRacket 5.3.6 this yields the following error:
>
> twice: contract violation
>  expected: number?
>  given: 'foo
>  in: the 1st argument of
>       (-> number? number?)
>  contract from: (function twice)
>  blaming: .../blame-test.rkt
>  at: .../blame-test.rkt: 2.18
>
>
> The final line attributes blame to the twice function (line 2, col 18),
> but clearly the blame in this instance lies with the client code (line 6),
> consistent with the first six lines of the error message.
>
>
> This is a misinterpretation of the last line. If you read the entire
> message as a sentence, you will see that the "at: ..." means "this is where
> you find the contract that was broken". The "expected:"/"given" pairing
> means that the function was called, it expected a number, and the caller
> applied it to the symbol 'foo instead.
>
> If you run this program
>
> #lang racket
> (define/contract (twice x)
>   (-> number? number?)
>   'foo)
>
> (twice 2)
>
> the error message will say
>
> twice: broke its contract
>   promised: number?
>   produced: 'foo
>   in: the range of
>       (-> number? number?)
>   contract from: (function twice)
>   blaming: (function twice)
>   at: unsaved-editor665:2.18
>
> meaning that foo was called, it promised to return a number, but it
> produced the symbol 'foo instead.
>
> ;; ---
>
> I will admit that you're not the first one who has tripped over this error
> message [format] and that you aren't the last one. But changing it isn't
> easy and adding information isn't easy. The problem is that we wish to keep
> the messages uniform across all functions but not all functions can benefit
> from the actual contract system.
>
> -- Matthias
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130903/3b028b07/attachment.html>

Posted on the users mailing list.