Today,
I was playing with examples from wonderful Living Clojure book, chapter 5.
This is mainly stuff that I have already know, but I still did want to write down all code and try it by myself. There was no surprise until I got to the very end of chapter when there’s an example demonstrating usage of “:main” in project.clj.
Pretty trivial, huh?!
I did the appropriate changes to my project.clj:
(defproject wonderland "0.1.0-SNAPSHOT"
~ :description "Examples from the book Living Clojure by Carin Meier"
~ :url "https://github.com/jumarko/living-clojure"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
~ :dependencies [[org.clojure/clojure "1.8.0"]
~ [camel-snake-kebab "0.3.2"]]
~ :main wonderland.core)
and tried to execute lein run:
lein run
Exception in thread "main" java.lang.IllegalArgumentException: No implementation of method: :alter-name of protocol: #'camel-snake-kebab.internals.alter-name/AlterName found for class: nil, compiling:(/private/var/folders/hn/tgwyrdmj1tb5pmmbdkd1g_qc0000gn/T/form-init2789214926070543937.clj:1:125)
at clojure.lang.Compiler.load(Compiler.java:7391)
at clojure.lang.Compiler.loadFile(Compiler.java:7317)
at clojure.main$load_script.invokeStatic(main.clj:275)
at clojure.main$init_opt.invokeStatic(main.clj:277)
at clojure.main$init_opt.invoke(main.clj:277)
at clojure.main$initialize.invokeStatic(main.clj:308)
at clojure.main$null_opt.invokeStatic(main.clj:342)
at clojure.main$null_opt.invoke(main.clj:339)
at clojure.main$main.invokeStatic(main.clj:421)
at clojure.main$main.doInvoke(main.clj:384)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at clojure.lang.Var.invoke(Var.java:383)
at clojure.lang.AFn.applyToHelper(AFn.java:156)
at clojure.lang.Var.applyTo(Var.java:700)
at clojure.main.main(main.java:37)
Caused by: java.lang.IllegalArgumentException: No implementation of method: :alter-name of protocol: #'camel-snake-kebab.internals.alter-name/AlterName found for class: nil
at clojure.core$_cache_protocol_fn.invokeStatic(core_deftype.clj:568)
at clojure.core$_cache_protocol_fn.invoke(core_deftype.clj:560)
at camel_snake_kebab.internals.alter_name$eval3006$fn__3007$G__2997__3014.invoke(alter_name.clj:4)
at camel_snake_kebab.core$__GT_snake_case.invokeStatic(core.clj:20)
at camel_snake_kebab.core$__GT_snake_case.doInvoke(core.clj:20)
at clojure.lang.RestFn.invoke(RestFn.java:410)
at wonderland.core$serpent_talk.invokeStatic(core.clj:5)
at wonderland.core$serpent_talk.invoke(core.clj:4)
at wonderland.core$_main.invokeStatic(core.clj:9)
at wonderland.core$_main.doInvoke(core.clj:7)
at clojure.lang.RestFn.invoke(RestFn.java:397)
at clojure.lang.Var.invoke(Var.java:375)
at user$eval2877.invokeStatic(form-init2789214926070543937.clj:1)
at user$eval2877.invoke(form-init2789214926070543937.clj:1)
at clojure.lang.Compiler.eval(Compiler.java:6927)
at clojure.lang.Compiler.eval(Compiler.java:6917)
at clojure.lang.Compiler.load(Compiler.java:7379)
... 14 more
Holly shit! The example uses the camel-snake-kebab library, but what does this mean?!
Caused by: java.lang.IllegalArgumentException: No implementation of method: :alter-name of protocol: #'camel-snake-kebab.internals.alter-name/AlterName
Since I was not able to decrypt this message, I started to look for the solution on the internet. I found two stackoverflow questions:
I found that I misspeled the name of main function – instead of (defn -main...) I had (defn- main). I fixed the signature of main method, but problem persisted.
I triple-checked that I had spelled the name of my namespace in the project.clj correctly. I also tried to play with project.clj adding various stuff like ^:skip-aot, etc. Obviously, this didnt’ help.
More than half hour later, it suddenly came: I forgot to pass the argument on command line!
This is my namespace with main method:
(ns wonderland.talk
(:require [camel-snake-kebab.core :as csk]))
(defn serpent-talk [input]
(str "Serpent! You said: " ( csk/->snake_case input)))
(defn -main [& args]
(println (serpent-talk (first args))))
serpernt-talk function that is called within -main method expects one argument. It didn’t get any and failed with mysterious error message.
Once I supplied proper argument, everything was OK:
lein run "Hello"
Serpent! You said: hello
That is! Sometimes, the Clojure error messages are really cryptic – at least for me.