Alright so the bug appears in Clojure 1.5.0-RC1 - I'm not sure whether this
is a regression or intended behaviour so I'll send a separate email to the
list about that.

In the meantime I've applied a fix and pushed [bouncer "0.2.2-RC2"]

With this change I'm also using lein profiles to run the tests against
Clojure 1.3, 1.4 and 1.5-RC1 - The README has a build status indicator from
travis.ci. This should prevent version bugs like this one from appearing in
the future.

Thanks for the report,
Cheers

Leonardo Borges
www.leonardoborges.com


On Tue, Jan 15, 2013 at 9:51 AM, Leonardo Borges <
leonardoborges...@gmail.com> wrote:

> Hi Gary,
>
> Thanks for the bug report.
>
> Which version of Clojure causes the issue? I've been using Clojure 1.4 and
> the exact snippet you posted works flawlessly. As well as bouncer, given I
> have test cases around validators with no explicit messages.
>
>
> Cheers,
>
> Leonardo Borges
> www.leonardoborges.com
>
>
> On Tue, Jan 15, 2013 at 7:52 AM, Gary Johnson <gwjoh...@uvm.edu> wrote:
>
>> Hey Leonardo,
>>
>>   There's a critical bug in 0.2.2-RC1 in the bouncers.core/wrap function.
>> An IllegalArgumentException is triggered whenever a validator is not passed
>> an explicit :message field. It looks like this was introduced in the
>> process of trying to allow validators to take an arbitrary number of input
>> args (a very good thing IMO). Here's a minimum case for replicating this
>> error at your repl:
>>
>> (let [{:keys [message] :or {message "foo"}} '()] message)
>> IllegalArgumentException No value supplied for key: null
>> clojure.lang.PersistentHashMap.create (PersistentHashMap.java:77)
>>
>> This is being triggered in your wrap function when you apply map
>> destructuring to the right-hand result of (split-with (complement keyword?)
>> args). Anyway, here is a patched version of wrap that should fix the
>> problem. FWIW, I also fixed the docstring typo "erros" -> "errors".
>>
>> (defn wrap
>>   "Wraps pred in the context of validating a single value
>>
>>   - `acc`  is the map being validated
>>
>>   - `pred` is a validator
>>
>>   - `k`    the path to the value to be validated in the associative
>> structure acc
>>
>>   - `args` any extra args to pred
>>
>>   It only runs pred if:
>>
>>   - the validator is optional *and* there is a non-nil value to be
>> validated (this information is read from pred's metadata)
>>
>>   - there are no previous errors for the given path
>>
>>   Returns `acc` augmented with a namespace qualified ::errors keyword
>> "
>>   [acc [pred k & args]]
>>   (let [pred (h/resolve-or-same pred)
>>         k (if (vector? k) k [k])
>>         error-path (cons ::errors k)
>>         {:keys [default-message-format optional]} (meta pred)
>>         [args message-kv] (split-with (complement keyword?) args)
>>         message (get (apply hash-map message-kv) :message
>> default-message-format)
>>         pred-subject (get-in acc k)]
>>     (if (or (and optional (nil? pred-subject))
>>             (not (empty? (get-in acc error-path)))
>>             (apply pred pred-subject args))
>>       acc
>>       (update-in acc error-path
>>                  #(conj % (format message (name (peek k))))))))
>>
>> Cheers,
>>   ~Gary
>>
>>
>>
>> On Sunday, January 13, 2013 8:03:36 PM UTC-5, Leonardo Borges wrote:
>>
>>> Thanks, really appreciate the kind words.
>>>
>>> I just pushed [bouncer "0.2.2-RC1"] so feel free to give that a go :)
>>>
>>> Cheers,
>>> Leo
>>>
>>> Leonardo Borges
>>> www.leonardoborges.com
>>>
>>>
>>> On Fri, Jan 11, 2013 at 3:44 PM, faenvie <fanny....@gmx.de> wrote:
>>>
>>>>
>>>> i took a look at it. bouncers DSL seems smart inside and out.
>>>> Has an excellent Documentation too. Thanks for sharing it.
>>>>
>>>>  --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Clojure" group.
>>>> To post to this group, send email to clo...@googlegroups.com
>>>>
>>>> Note that posts from new members are moderated - please be patient with
>>>> your first post.
>>>> To unsubscribe from this group, send email to
>>>> clojure+u...@**googlegroups.com
>>>>
>>>> For more options, visit this group at
>>>> http://groups.google.com/**group/clojure?hl=en<http://groups.google.com/group/clojure?hl=en>
>>>>
>>>
>>>  --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clojure@googlegroups.com
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>>
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to