Improving error messages for non-serializable continuation pieces
This commit is contained in:
parent
cc86b6f06e
commit
c2065b2128
17
collects/tests/web-server/pr/12183.rkt
Normal file
17
collects/tests/web-server/pr/12183.rkt
Normal 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"))
|
|
@ -41,8 +41,21 @@
|
||||||
(insert-param uri URL-KEY (bytes->string/utf-8 c)))
|
(insert-param uri URL-KEY (bytes->string/utf-8 c)))
|
||||||
|
|
||||||
(define (stuff-url stuffer uri c)
|
(define (stuff-url stuffer uri c)
|
||||||
(insert-in-uri
|
(with-handlers
|
||||||
uri ((stuffer-in stuffer) c)))
|
([(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)
|
(define (stuffed-url? uri)
|
||||||
(string? (extract-param uri URL-KEY)))
|
(string? (extract-param uri URL-KEY)))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user