relevance/labrepl

Labs fail to load because (name lab) throws ClassCastException

Closed this issue · 3 comments

Steps to reproduce:

  1. launch labrepl with scripts/repl
  2. navigate to http://localhost:8080 in your browser
  3. visit one of the labs (ie: intro)
  4. observe traceback on the page as well as the labrepl console

The traceback begins as follows:

java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.Named
    at clojure.core$name__4021.invoke(core.clj:1227)
    at labrepl.lab$instructions__1728.invoke(lab.clj:20)
    ...

At line 20 of src/labrepl/lab.clj is the following code:

(let [lab-ns (symbol (str "labs." (name lab)))]

The var lab is a String. In SHA: 3149fdd this line is changed from:

(let [lab-ns (symbol (str "labs." (as-str lab)))]

I guess as-str and name behave differently if their argument is a String. Note that only the argument to labrepl.lab.instructions is a String; labrepl.lab.lab-url and labrepl.lab.url all receive Keyword instances.

This patch fixes the problem

diff --git a/src/labrepl/lab.clj b/src/labrepl/lab.clj
index 83d00dc..a873504 100644
--- a/src/labrepl/lab.clj
+++ b/src/labrepl/lab.clj
@@ -17,7 +17,7 @@

 (defn instructions
   [lab]
-  (let [lab-ns (symbol (str "labs." (name lab)))]
+  (let [lab-ns (symbol (str "labs." lab))]
     (require lab-ns)
     ((ns-resolve lab-ns 'instructions))))

You need a more recent version of clojure.jar.

Of course, you're right.

Here's what happened. I tried labrepl last month, so coming back to it yesterday I first ran git pull to get the latest changes, then lein deps to pull down the latest dependencies. This pulled down clojure-1.2.0-master-20100607.150309-85.jar but left the clojure-1.2.0-master-20100504.200313-67.jar from before lying around. When the repl launched, it must have pulled in the old version since it's first in lexicographical order.

Another gotcha to watch out for in the future.