I have the same issue for ->i contracts. I'll write multiple #:pre/desc checks with nice messages, which are promptly rendered useless by the fact that ->i prints out the whole contract instead of just the precondition check that failed. On Friday, October 30, 2020 at 7:16:59 PM UTC-7 Ben Greenman wrote:
> > Ben: if you have an example of the bad hash/dc error message I'd be > > interested to see it. > > > > Robby > > Here's the kind of message that turned me off: > > ``` > ctc.rkt:34:0: broke its own contract > promised: (hash/dc (k (or/c (quote a) (quote b) (quote c))) (v (k) > (config-value/c k)) #:immutable #t #:kind (quote flat)) > produced: '#hash((a . 1) (b . #t) (c . #<void>)) > in: (hash/dc > (k (or/c 'a 'b 'c)) > (v (k) (config-value/c k)) > #:immutable > #t > #:kind > 'flat) > contract from: + > blaming: + > (assuming the contract is correct) > ``` > > It prints the whole hash and contract, leaving me to figure out the > two key parts: (1) what piece of the hash failed, and (2) what the > contract expected for that piece. > > Now that I think of it ->* is bad in the same way --- especially for > `plot` functions. > > > Here's the code that made that error message. The #;(lambda ....) > comment is the contract that I ended up using instead of hash/dc (it > still doesn't explain bad values well). > > ``` > #lang racket/base > > (require racket/contract) > > (provide config/c) > > (define config-key/c > (or/c 'a 'b 'c)) > > (define (config-value/c k) > (case k > ((a) > string?) > ((b) > boolean?) > ((c) > void?))) > > (define config/c > #;(lambda (h) > (for ((k (in-list (list 'a 'b 'c)))) > (unless (hash-has-key? h k) > (raise-arguments-error 'config/c "missing key" "key" k "hash" h)) > (define v (hash-ref h k)) > (unless ((config-value/c k) v) > (raise-arguments-error 'config/c "bad value for key" "key" k > "value" v "hash" h)) > (void))) > (hash/dc > [k config-key/c] > [v (k) (config-value/c k)] > #:immutable #true > #:kind 'flat)) > > (contract > config/c > (hash 'a 1 'b #true 'c (void)) > '+ > '-) > ``` > -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/3b0ed32b-4875-4cfa-9b2b-e4398e4318d1n%40googlegroups.com.

