weavejester / codox

Clojure documentation tool
Eclipse Public License 1.0
667 stars 96 forks source link

java.lang.IllegalArgumentException: /tmp/form-init5038495816670430674.clj is not a relative path #43

Closed vbauer closed 10 years ago

vbauer commented 10 years ago

I've got this exception during documentation generation:

Exception in thread "main" java.lang.IllegalArgumentException: /tmp/form-init5038495816670430674.clj is not a relative path
    at clojure.java.io$as_relative_path.invoke(io.clj:404)
    at clojure.java.io$file.invoke(io.clj:415)
    at codox.utils$find_file_in_repo$fn__32.invoke(utils.clj:23)
    at clojure.core$map$fn__4207.invoke(core.clj:2485)
    at clojure.lang.LazySeq.sval(LazySeq.java:42)
    at clojure.lang.LazySeq.seq(LazySeq.java:60)
    at clojure.lang.RT.seq(RT.java:484)
    at clojure.core$seq.invoke(core.clj:133)
    at clojure.core$filter$fn__4226.invoke(core.clj:2523)
    at clojure.lang.LazySeq.sval(LazySeq.java:42)
    at clojure.lang.LazySeq.seq(LazySeq.java:60)
    at clojure.lang.LazySeq.first(LazySeq.java:82)
    at clojure.lang.RT.first(RT.java:577)
    at clojure.core$first.invoke(core.clj:55)
    at codox.utils$find_file_in_repo.invoke(utils.clj:23)
    at codox.utils$add_source_paths$iter__44__48$fn__49$fn__55.invoke(utils.clj:70)
    at clojure.core$map$fn__4207.invoke(core.clj:2487)
    at clojure.lang.LazySeq.sval(LazySeq.java:42)
    at clojure.lang.LazySeq.seq(LazySeq.java:60)
    at clojure.lang.RT.seq(RT.java:484)
    at clojure.core$seq.invoke(core.clj:133)
    at clojure.core$map$fn__4207.invoke(core.clj:2479)
    at clojure.lang.LazySeq.sval(LazySeq.java:42)
    at clojure.lang.LazySeq.seq(LazySeq.java:60)
    at clojure.lang.RT.seq(RT.java:484)
    at clojure.core$seq.invoke(core.clj:133)
    at hiccup.element$unordered_list$iter__526__530$fn__531.invoke(element.clj:27)
    at clojure.lang.LazySeq.sval(LazySeq.java:42)
    at clojure.lang.LazySeq.seq(LazySeq.java:60)
    at clojure.lang.RT.seq(RT.java:484)
    at clojure.core$seq.invoke(core.clj:133)
    at clojure.core$map$fn__4207.invoke(core.clj:2479)
    at clojure.lang.LazySeq.sval(LazySeq.java:42)
    at clojure.lang.LazySeq.seq(LazySeq.java:60)
    at clojure.lang.RT.seq(RT.java:484)
    at clojure.core$seq.invoke(core.clj:133)
    at clojure.core$apply.invoke(core.clj:617)
    at hiccup.compiler$eval244$fn__245.invoke(compiler.clj:82)
    at hiccup.compiler$eval212$fn__213$G__203__218.invoke(compiler.clj:62)
    at clojure.core$map$fn__4207.invoke(core.clj:2485)
    at clojure.lang.LazySeq.sval(LazySeq.java:42)
    at clojure.lang.LazySeq.seq(LazySeq.java:60)
    at clojure.lang.RT.seq(RT.java:484)
    at clojure.core$seq.invoke(core.clj:133)
    at clojure.core$apply.invoke(core.clj:617)
    at hiccup.compiler$eval244$fn__245.invoke(compiler.clj:82)
    at hiccup.compiler$eval212$fn__213$G__203__218.invoke(compiler.clj:62)
    at hiccup.compiler$render_element.invoke(compiler.clj:72)
    at hiccup.compiler$eval248$fn__249.invoke(compiler.clj:79)
    at hiccup.compiler$eval212$fn__213$G__203__218.invoke(compiler.clj:62)
    at clojure.lang.Var.invoke(Var.java:415)
    at codox.writer.html$index_page$iter__651__655$fn__656.invoke(html.clj:68)
    at clojure.lang.LazySeq.sval(LazySeq.java:42)
    at clojure.lang.LazySeq.seq(LazySeq.java:60)
    at clojure.lang.Cons.next(Cons.java:39)
    at clojure.lang.RT.boundedLength(RT.java:1654)
    at clojure.lang.RestFn.applyTo(RestFn.java:130)
    at clojure.core$apply.invoke(core.clj:617)
    at codox.writer.html$index_page.invoke(html.clj:78)
    at codox.writer.html$write_index.invoke(html.clj:128)
    at codox.writer.html$write_docs.invoke(html.clj:139)
    at clojure.lang.Var.invoke(Var.java:415)
    at codox.main$generate_docs.invoke(main.clj:28)
    at user$eval114.invoke(form-init5038495816670430674.clj:1)
    at clojure.lang.Compiler.eval(Compiler.java:6619)
    at clojure.lang.Compiler.eval(Compiler.java:6609)
    at clojure.lang.Compiler.load(Compiler.java:7064)
    at clojure.lang.Compiler.loadFile(Compiler.java:7020)
    at clojure.main$load_script.invoke(main.clj:294)
    at clojure.main$init_opt.invoke(main.clj:299)
    at clojure.main$initialize.invoke(main.clj:327)
    at clojure.main$null_opt.invoke(main.clj:362)
    at clojure.main$main.doInvoke(main.clj:440)
    at clojure.lang.RestFn.invoke(RestFn.java:421)
    at clojure.lang.Var.invoke(Var.java:419)
    at clojure.lang.AFn.applyToHelper(AFn.java:163)
    at clojure.lang.Var.applyTo(Var.java:532)
    at clojure.main.main(main.java:37)

PS: As result I got CSS and JS files in the "doc" directory without HTML files.

weavejester commented 10 years ago

How are you using Codox? At first glance it looks like you might be executing it from the REPL.

vbauer commented 10 years ago

I do the following things:

vbauer@vladislav-bauer:~/workspace/clojure/ziggurat$ lein clean
vbauer@vladislav-bauer:~/workspace/clojure/ziggurat$ lein doc
Compiling ziggurat.db
2014-Mar-22 18:16:12 +0700 vladislav-bauer INFO [ziggurat.db] - Init Lua scripts
2014-Mar-22 18:16:12 +0700 vladislav-bauer INFO [ziggurat.db] - Init Lua script: create-post
2014-Mar-22 18:16:12 +0700 vladislav-bauer INFO [ziggurat.db] - Init Lua script: find-all-tags
2014-Mar-22 18:16:12 +0700 vladislav-bauer INFO [ziggurat.db] - Init Lua script: find-all-posts
Compiling ziggurat.ui.handler
Compiling ziggurat.ui.routes
Compiling ziggurat.app
Compiling ziggurat.rules.output
Compiling ziggurat.rules.data
Compiling ziggurat.rules.engine
Compiling ziggurat.core
Exception in thread "main" java.lang.IllegalArgumentException: /tmp/form-init9096339398177041302.clj is not a relative path
    at clojure.java.io$as_relative_path.invoke(io.clj:404)
    at clojure.java.io$file.invoke(io.clj:415)
    at codox.utils$find_file_in_repo$fn__32.invoke(utils.clj:23)
    at clojure.core$map$fn__4207.invoke(core.clj:2485)
    at clojure.lang.LazySeq.sval(LazySeq.java:42)
    at clojure.lang.LazySeq.seq(LazySeq.java:60)
...
Subprocess failed

My project.clj is very simple (it's a sandbox project):

(defproject
  ziggurat
  "0.1.0-SNAPSHOT"
  :dependencies
  [[ring-server "0.3.1"]
   [ring/ring-json "0.2.0"]
   [com.taoensso/timbre "3.1.5"]
   [http-kit "2.1.17"]
   [com.taoensso/tower "2.0.1"]
   [org.clojure/clojure "1.5.1"]
   [compojure "1.1.6"]
   [lib-noir "0.7.9"]
   [com.postspectacular/rotor "0.1.0"]
   [com.taoensso/carmine "2.4.6"]
   [org.drools/drools-compiler "6.0.1.Final"]
   [org.drools/knowledge-api "6.0.1.Final"]
   [clj-http "0.9.0"]
   [com.sun.xml/jaxb-xjc "2.0EA3"]
   [org.jsoup/jsoup "1.7.3"]
   [org.apache.commons/commons-lang3 "3.3"]
   [ch.qos.logback/logback-classic "1.1.1"]
   [com.ibm.icu/icu4j "52.1"]
   [com.googlecode.juniversalchardet/juniversalchardet "1.0.3"]]

  :url "http://example.com/FIXME"
  :main ziggurat.app
  :aot :all
  :plugins [[lein-kibit "0.0.8"] [codox "0.6.7"]]
  :description "FIXME: write description"
  :min-lein-version "2.0.0")
weavejester commented 10 years ago

Okay, so it looks like there's a var created in ziggurat.core that has some odd metadata. Instead of having a :path of ziggurat/core.clj, it's /tmp/form-init9096339398177041302.clj, something you'd typically see from a form created in the REPL.

Could I see the ziggurat.core namespace?

vbauer commented 10 years ago

Yes, ofc:

(ns ziggurat.core
  ^{:author "Vladislav Bauer"}
  (:import (org.apache.commons.lang3 StringUtils)
           (com.ibm.icu.text CharsetDetector)
           (org.mozilla.universalchardet UniversalDetector)
           (java.io BufferedOutputStream FileOutputStream))
  (:require [clj-http.client :as client]
            [clojure.string :as string]
            [taoensso.timbre :as timbre]))

; Configuration

(def config {:dev-mode true
             :http-port 8080
             :screenshot-service "http://localhost:8081/"
             :images-directory "data/images/"
             :width 800
             :height 600
             :default-charset "UTF-8"
             :http-client-params {:insecure? true
                                  :follow-redirects true
                                  :max-redirects 5
                                  :socket-timeout 10000
                                  :conn-timeout 10000
                                  :decode-body-headers true
                                  :as :byte-array}})

; Core macros and functions

(defmacro safe [& body]
  `(try ~@body
     (catch Throwable e#
       ;(timbre/error e#)
       nil)))

(defn defval [v d] (if (nil? v) d v))

(defn lower-case-map [data]
  (into {} (for [[k v] data] [(string/lower-case k) v])))

(defn has-part [content-type & types]
  (some #(.contains content-type %) types))

; Character & encodings

(defn- detect-charset-icu [data]
  (let [detector (doto (CharsetDetector.)
                   (.setText data)
                   (.enableInputFilter true))]
    (.getName (.detect detector))))

(defn- detect-charset-universal [data]
  (let [detector (doto (UniversalDetector. nil)
                   (.handleData data 0 (count data))
                   (.dataEnd))]
    (.getDetectedCharset detector)))

(defn detect-charset [data]
  (let [processor #(StringUtils/upperCase (% data))
        detectors [detect-charset-universal]
        charsets (remove nil? (map processor detectors))]
    (if (= 1 (count charsets))
      (first charsets)
      (:default-charset config))))

(defn as-utf8 [data] (String. data (detect-charset data)))

; Network functions

(defn parse-query-params [url]
  (let [query (.getQuery url)
        params (string/split (StringUtils/trimToEmpty query) #"&")
        kv (map #(string/split % #"=") params)]
    (try (into {} kv) (catch Exception ex nil))))

(defn send-request [url]
  (client/get url (:http-client-params config)))

; File functions

(defn write-file [file data]
  (with-open [writer (BufferedOutputStream. (FileOutputStream. file))]
    (.write writer data)))
weavejester commented 10 years ago

Looking it over, nothing strikes me as hugely unusual, except:

^{:author "Vladislav Bauer"}

Which should be:

{:author "Vladislav Bauer"}

I'm not sure whether that's causing the issue, but you could try it.

I'll try adding the code to a local project and see if I can reproduce the error.

vbauer commented 10 years ago

It looks like http://en.wikibooks.org/wiki/Learning_Clojure/Meta_Data contains wrong information about "^{:author ""}".

Thank you for idea, I tried to:

but it didn't help me..

It's a little bit strange that I see twice the following logs:

2014-Mar-23 14:05:57 +0700 vladislav-bauer INFO [ziggurat.db] - Init Lua scripts
2014-Mar-23 14:05:57 +0700 vladislav-bauer INFO [ziggurat.db] - Init Lua script: create-post
2014-Mar-23 14:05:57 +0700 vladislav-bauer INFO [ziggurat.db] - Init Lua script: find-all-tags
2014-Mar-23 14:05:57 +0700 vladislav-bauer INFO [ziggurat.db] - Init Lua script: find-all-posts

I write this messages in ziggurat.db, but only once:

(def lua-scripts (atom (reload-lua-scripts lua-files)))
weavejester commented 10 years ago

The wikibook is correct. It advocates writing:

(ns ^{:author "Vladislav Bauer"} ziggurat.core)

This is because you're placing the metadata on the namespace symbol. In later versions of Clojure, you can also write:

(ns ziggurat.core {:author "Vladislav Bauer"})

Regarding the error, I've tried reproducing it with the code you provided, but everything works fine for me. However, I notice you have :aot :all in your project file. With AOT you have to be careful, as it can result in obsolete class files cluttering up your namespace. This may be what's causing your strange error.

Try running:

lein clean

And then see if lein doc works after that.

If that doesn't work, try removing the target directory entirely, and then trying lein doc.

vbauer commented 10 years ago

Thank you for information!

As I said before I've tried to make clean:

vbauer@vladislav-bauer:~/workspace/clojure/ziggurat$ lein clean
vbauer@vladislav-bauer:~/workspace/clojure/ziggurat$ lein doc

(I also tried to remove target directory instead of cleaning)

I've tried to change ":aot" parameter, but it did not help:

  :main ziggurat.app
  :aot [ziggurat.rules.data ziggurat.rules.output ziggurat.app]

It looks like I found problem.. In the namespace ziggurat.db I have atom with list of some data. The value for this atom is retrieved using function "reload-lua-scripts". I also create some functions in this namespace in run-time using specific macros. When I comment this code (def lua-scripts (atom (reload-lua-scripts lua-files))) and all calls to this "created in runtime" functions - everything works fine.

ziggurat.db:

(ns ziggurat.db
  (:require [taoensso.timbre :as timbre]
            [taoensso.carmine :as car  :refer (wcar)]
            [cheshire.core :as json]))

; Common Redis

(def server-connection {:pool {} :spec {}})
(defmacro wcar* [& body]
  `(car/wcar server-connection ~@body))

; Common Lua

(declare lua-scripts)
(declare run-lua-script)

(defmacro def-lua-script [name]
  (timbre/info (str "Init Lua script: " name))
  `(defn ~(symbol name) [& argv#] (run-lua-script ~name argv#)))

(defn- load-lua-script [name]
  (let [fname (str "db/" name ".lua")
        source (slurp (clojure.java.io/resource fname))
        checksum (car/script-hash source)]
    {:name name :source source :checksum checksum}))

(defn- reload-lua-scripts [files]
  (timbre/info "Init Lua scripts")
  (let [scripts (map load-lua-script files)]
    (wcar*
      (car/redis-call [:script "flush"])
      (doseq [script scripts]
        (car/redis-call [:script "load" (:source script)])
        (let [sn (:name script)]
          (eval `(def-lua-script ~sn)))))
    scripts))

(defn- run-lua-script [name & argv]
  (let [script (first (filter #(= (:name %) name) @lua-scripts))
        checksum (:checksum script)
        args (flatten argv)]
    (timbre/debug "Run script" name "with arguments" args)
    (json/parse-string (wcar* (apply car/evalsha checksum 0 args)))))

(def lua-files ["create-post" "find-all-tags" "find-all-posts"])
(def lua-scripts (atom (reload-lua-scripts lua-files)))

I hope that I explained it clearly..