robert-hooke icon indicating copy to clipboard operation
robert-hooke copied to clipboard

Arity Exception when calling add-hook

Open lkrubner opened this issue 10 years ago • 8 comments

This originally started because I introduced Dire to a project, which had an out of date version of robert-hooke. But I updated the dependencies, which I though would fix the problem, but it does not.

If I:

(ns admin.views (:use [taoensso.timbre :as timbre :only (trace debug info warn error fatal spy)] [robert.hooke]))

and:

(add-hook #'process-programmer-designer-contract java.lang.ArithmeticException #'microscope)

And then, in emacs, I try:

nrepl-jack-in

which gives me:

Exception in thread "main" java.lang.ExceptionInInitializerError ...Caused by: clojure.lang.ArityException: Wrong number of args (3) passed to: hooke$add-hook

If I look here:

https://github.com/technomancy/robert-hooke/blob/master/src/robert/hooke.clj

I see:

(defn add-hook "Add a hook function f to target-var. Hook functions are passed the target function and all their arguments and must apply the target to the args if they wish to continue execution." ([target-var f](add-hook target-var f f)) ([target-var key f](prepare-for-hooks target-var) (possibly-record-in-scope target-var) (swap! (hooks target-var) assoc key f)))

This clearly accepts 3 args.

If I try to do it like this:

(ns admin.views (:require [robert.hooke :as hooke]))

(hooke/add-hook #'process-programmer-designer-contract java.lang.ArithmeticException #'microscope)

I get the same error.

I can call add-hook with 2 arguments and that works just fine:

(hooke/add-hook #'process-programmer-designer-contract #'microscope)

If I do this:

lein deps :tree

The only dependencies I see are the ones I expect:

[cheshire "5.1.1"] [com.fasterxml.jackson.core/jackson-core "2.1.4"] [com.fasterxml.jackson.dataformat/jackson-dataformat-smile "2.1.4"] [clj-time "0.4.4"] [joda-time "2.1"] [com.cemerick/friend "0.1.5"] [com.google.inject/guice "2.0"] [aopalliance "1.0"] [commons-codec "1.6"] [net.sourceforge.nekohtml/nekohtml "1.9.10"] [xerces/xercesImpl "2.8.1"] [xml-apis "1.3.03"] [org.apache.httpcomponents/httpclient "4.2.1"] [org.apache.httpcomponents/httpcore "4.2.1"] [org.clojure/core.cache "0.6.2"] [org.clojure/core.incubator "0.1.1"] [org.mindrot/jbcrypt "0.3m"] [org.openid4java/openid4java-nodeps "0.9.6" :exclusions [[com.google.code.guice/guice]]] [commons-logging "1.1.1"] [net.jcip/jcip-annotations "1.0"] [ring/ring-core "1.2.0-beta1"] [commons-fileupload "1.2.2"] [commons-io "2.4"] [javax.servlet/servlet-api "2.5"] [ring/ring-codec "1.0.0"] [com.novemberain/monger "1.4.2"] [clojurewerkz/support "0.10.0"] [com.google.guava/guava "12.0"] [com.google.code.findbugs/jsr305 "1.3.9"] [com.novemberain/validateur "1.2.0"] [org.mongodb/mongo-java-driver "2.10.1"] [ragtime/ragtime.core "0.3.0"] [org.clojure/tools.cli "0.2.2"] [com.taoensso/timbre "1.2.0"] [clj-stacktrace "0.2.5"] [compojure "1.1.5"] [clout "1.0.1"] [org.clojure/tools.macro "0.1.0"] [dire "0.4.4"] [robert/hooke "1.3.0"] [slingshot "0.10.3"] [enlive "1.0.1"] [org.ccil.cowan.tagsoup/tagsoup "1.2"] [formative "0.7.0"] [jkkramer/verily "0.5.4"] [org.clojure/clojurescript "0.0-1843"] [com.google.javascript/closure-compiler "r2180"] [args4j "2.0.16"] [com.google.protobuf/protobuf-java "2.4.1"] [com.googlecode.jarjar/jarjar "1.1"] [org.apache.ant/ant "1.8.2"] [org.apache.ant/ant-launcher "1.8.2"] [org.json/json "20090211"] [org.clojure/google-closure-library "0.0-2029-2"] [org.clojure/google-closure-library-third-party "0.0-2029-2"] [org.mozilla/rhino "1.7R4"] [prismatic/dommy "0.1.1"] [crate "0.2.3" :scope "dev"] [prismatic/cljs-test "0.0.5"] [fs "1.3.2"] [org.apache.commons/commons-compress "1.3"] [org.clojure/clojure "1.5.1"] [org.clojure/data.json "0.2.0"] [org.clojure/java.classpath "0.2.0"] [org.clojure/tools.namespace "0.2.3"] [ring/ring-jetty-adapter "1.1.5"] [org.eclipse.jetty/jetty-server "7.6.1.v20120215"] [org.eclipse.jetty.orbit/javax.servlet "2.5.0.v201103041518"] [org.eclipse.jetty/jetty-continuation "7.6.1.v20120215"] [org.eclipse.jetty/jetty-http "7.6.1.v20120215"] [org.eclipse.jetty/jetty-io "7.6.1.v20120215"] [org.eclipse.jetty/jetty-util "7.6.1.v20120215"] [ring "1.1.5"] [ring/ring-devel "1.1.5"] [hiccup "1.0.0"] [ns-tracker "0.1.2"] [ring/ring-servlet "1.1.5"]

Any thoughts about what is going wrong?

If I run "lein uberjar" it seems to compile, but at the repl it blows up.

lkrubner avatar Sep 09 '13 02:09 lkrubner

Can't reproduce, perhaps I've got the wrong idea.

(ns dire-error.core
  (:require [robert.hooke :as r]
            [dire.core :as d]))

(defn foo
  [x]
  x)

(defn microscope
  [f x]
  (inc x))

(r/add-hook #'foo java.lang.ArithmeticException #'microscope)

Project file:

(defproject dire-error "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.5.1"]
                 [dire "0.4.4"]
                 [robert/hooke "1.3.0"]])

MichaelDrogalis avatar Sep 09 '13 14:09 MichaelDrogalis

It is a strange error for sure. I'm reaching for straws here. Could there be some coflict with another library? Or development setting? My project.clj right now is:

(defproject admin "0.1" :description "This is the admin dashboard that provides a GUI through which TMA staff can interact with the database that powers TMA." :license {:name "Copyright Lawrence Krubner 2013"} :dependencies [[org.clojure/clojure "1.5.1"] [dire "0.4.4"] [com.cemerick/friend "0.1.5"] [ring "1.1.5"] [ring/ring-jetty-adapter "1.1.5"] [clj-time "0.4.4"] [org.clojure/data.json "0.2.0"] [enlive "1.0.1"] [compojure "1.1.5"] [cheshire "5.1.1"] [com.novemberain/monger "1.4.2"] [com.taoensso/timbre "1.2.0"] [org.clojure/tools.namespace "0.2.4"] [formative "0.7.0"]] :profiles {:dev {:source-paths ["dev"] :dependencies [[org.clojure/tools.namespace "0.2.3"] [org.clojure/java.classpath "0.2.0"]]}} :repositories [["central-proxy" "https://repository.sonatype.org/content/repositories/centralm1/"]] :disable-implicit-clean true :main admin.core :jvm-opts ["-Xms512m" "-Xmx2000m" "-XX:-UseCompressedOops"])

lkrubner avatar Sep 09 '13 17:09 lkrubner

I don't see robert/hooke in your dependencies. Were you able to actually use it anyway? Or just a typo?

MichaelDrogalis avatar Sep 09 '13 17:09 MichaelDrogalis

Okay, fixed now. Sorry for the trouble. I had to run "lein clean".

I notice that the code from 2 years ago:

https://github.com/technomancy/robert-hooke/blob/7086224d49dc86871cdf1284adb89d38883b6eb6/src/robert/hooke.clj

Back then, add-hook only took 2 arguments. When I started my current project, the project had that old version of hooke. I've tried and tried to delete that old version, but it was in the system somewhere. And yet this:

lein tree :deps

only showed hooke 1.3. Which confused me, because I thought if "lein tree :deps" didn't show an old version, then I must have been free of the old version.

But clearly, the ghost of hooke 1.2 was in the code somewhere. And "lein clean" fixed the problem.

lkrubner avatar Sep 09 '13 17:09 lkrubner

Maybe a problem in lein tree then. But good that it's resolved.

MichaelDrogalis avatar Sep 09 '13 17:09 MichaelDrogalis

Relevant.

MichaelDrogalis avatar Sep 09 '13 17:09 MichaelDrogalis

Ha! I like the poster you link to. I agree, there was some disparity between what "lein tree" showed me and what was actually there. When I have time, and if I can reproduce, I will file a bug with Leinengen.

lkrubner avatar Mar 09 '14 00:03 lkrubner

Sounds good.

MichaelDrogalis avatar Mar 09 '14 02:03 MichaelDrogalis