Clojure : “java.lang.IllegalArgumentException: No value supplied for key:” when I changed require

佐手、 提交于 2019-12-10 15:49:29

问题


I'm getting a java.lang.IllegalArgumentException: No value supplied for key: in my Clojure code.

I know this is what happens when I'm trying to destructure the keys in a mapping passed as an argument.

However, what's odd here is that this function has been working fine for ages, with the same data. And the only thing that seems to be different is how I'm now importing the function

Here's the error:

Caused by: java.lang.IllegalArgumentException: No value supplied for key: 
{:style {:color [255 150 150 255], :stroke-weight 2}, :points [[-1 0] [0 -1] [1 0] [0 1] [-1 0]]}

And here's the function that threw it.

(defn scale
  [val {:keys [style points]}]
  {:style style
   :points (scale-shape val points)})

In other words, I'm asking for the map to contain keys called style and points and it's being given a map which contains keys called style and points.

And this code has been working fine for months.

The difference is that I'm now calling it using sshapes/scale where sshapes was imported with:

 (:require [patterning.sshapes :as sshapes])

whereas previously I was just calling it as scale where scale came into the namespace using

 (:require [patterning.sshapes :refer :all])

Could this cause that kind of error?


回答1:


OK. I changed the code to use

(:require [patterning.sshapes :refer [scale rotate]])

ie. with the required functions named explicitly, did a lein clean, and the problem has disappeared. The function definitions themselves and the code which calls them remain the same.

Weird.



来源:https://stackoverflow.com/questions/24582624/clojure-java-lang-illegalargumentexception-no-value-supplied-for-key-when

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!