2016-07-12 4 views
-1

다음 Clojure 코드는 NPE를 발생시킵니다. stacktrace에서 이것은 >=이 호출 될 때 발생합니다. 왜 이런 일이 일어나는지 알 수는 없습니다.이 Clojure 코드로 인해 NPE가 발생하는 이유는 무엇입니까?

(def service-thresholds 
    [{:service "cpu idle" :invert true :warning 50 :critital 10} 
    {:service "cpu user" :invert false :warning 80 :critical 90}]) 

(defn threshold-check 
    [thresholds] 
    (fn [e] 
    (or (first (for [threshold thresholds 
        :when (= (:service threshold) (:service e))] 
       (assoc e :state 
         (if (not (:invert threshold)) 
          (condp <= (:metric e) 
          (:critical threshold) "critical" 
          (:warning threshold) "warning" 
          "ok") 
          (condp >= (:metric e) 
          (:critical threshold) "critical" 
          (:warning threshold) "warning" 
          "ok"))))) 
     e))) 

(println ((threshold-check service-thresholds) {:service "cpu idle" :metric 20 :state nil})) 

답변

3

:critital:critical의 정확한 철자 아니다.

+0

당신이 옳습니다! 나는 그것을 어떻게 보지 못했습니까! 고맙습니다. –

+1

그의 대답을 받아들입니다. – blushrt

관련 문제