From c2065b2128b37a2b796383177e84096bf3acce55 Mon Sep 17 00:00:00 2001 From: Jay McCarthy Date: Tue, 1 Nov 2011 09:58:06 -0600 Subject: [PATCH] Improving error messages for non-serializable continuation pieces --- collects/tests/web-server/pr/12183.rkt | 17 +++++++++++++++++ collects/web-server/lang/stuff-url.rkt | 17 +++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 collects/tests/web-server/pr/12183.rkt diff --git a/collects/tests/web-server/pr/12183.rkt b/collects/tests/web-server/pr/12183.rkt new file mode 100644 index 0000000000..018f3e3f90 --- /dev/null +++ b/collects/tests/web-server/pr/12183.rkt @@ -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 #) into a URL because it contains non-serializable pieces. Convert # to a serializable struct")) diff --git a/collects/web-server/lang/stuff-url.rkt b/collects/web-server/lang/stuff-url.rkt index f8b354dccc..09e5f2083b 100644 --- a/collects/web-server/lang/stuff-url.rkt +++ b/collects/web-server/lang/stuff-url.rkt @@ -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 ; given (.*)" + (exn-message x)))) + (lambda (x) + (define non + (second + (regexp-match #rx"serialize: expected argument of type ; 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)))