Improving error messages for non-serializable continuation pieces

This commit is contained in:
Jay McCarthy 2011-11-01 09:58:06 -06:00
parent cc86b6f06e
commit c2065b2128
2 changed files with 32 additions and 2 deletions

View File

@ -0,0 +1,17 @@
#lang racket
(require tests/eli-tester
net/url
web-server/lang/stuff-url
web-server/stuffers/stuffer
web-server/stuffers/serialize)
(struct not-serializable ())
(struct serializable (x) #:prefab)
(test
(stuff-url serialize-stuffer
(string->url "http://localhost:8000")
(serializable (not-serializable)))
=>
(error 'stuff-url "Cannot stuff '#s(serializable #<not-serializable>) into a URL because it contains non-serializable pieces. Convert #<not-serializable> to a serializable struct"))

View File

@ -41,8 +41,21 @@
(insert-param uri URL-KEY (bytes->string/utf-8 c)))
(define (stuff-url stuffer uri c)
(insert-in-uri
uri ((stuffer-in stuffer) c)))
(with-handlers
([(lambda (x)
(and (exn:fail? x)
(regexp-match #rx"serialize: expected argument of type <serializable object>; given (.*)"
(exn-message x))))
(lambda (x)
(define non
(second
(regexp-match #rx"serialize: expected argument of type <serializable object>; given (.*)"
(exn-message x))))
(error 'stuff-url
"Cannot stuff ~e into a URL because it contains non-serializable pieces. Convert ~a to a serializable struct"
c non))])
(insert-in-uri
uri ((stuffer-in stuffer) c))))
(define (stuffed-url? uri)
(string? (extract-param uri URL-KEY)))