yada icon indicating copy to clipboard operation
yada copied to clipboard

Partial functions for response functions fail

Open jamesmintram opened this issue 8 years ago • 4 comments

https://github.com/juxt/yada/blob/master/src/yada/util.clj#L241 returns 0 for a partial function. This leads to an Arity error when requesting the resource.

jamesmintram avatar Jun 13 '17 10:06 jamesmintram

Looks like the callstack I was getting was wrong. The error was caused several method calls deeper than the reponse fn - looks like the comment here is related? :) https://github.com/juxt/yada/blob/master/src/yada/methods.clj#L34

jamesmintram avatar Jun 13 '17 21:06 jamesmintram

Hi @jamesmintram - thanks for this report. The purpose of the code is to be a little more relaxed about calling response functions that don't have the exact signature - say you're not using the ctx you can use a no-args fn. The strategy is to attempt to call the (fn [ctx]) form first, for performance reasons, and then try other forms. However, if there's an ArityException in your response function, then this might lead to the function being called twice.

malcolmsparks avatar Jun 14 '17 14:06 malcolmsparks

Reopening to consider whether to remove this code strategy and require response functions to be single-arity.

malcolmsparks avatar Jun 14 '17 14:06 malcolmsparks

If single arity response functions were to be enforced, then the "arity" method would need to handle the case of partially applied functions too (instead of returning 0).

I "fixed" this problem in my fork... but I do not know whether it is a good fix or bad one :) I can share it later when I have access to my machine at home.

jamesmintram avatar Jun 14 '17 14:06 jamesmintram