pandeiro / boot-http

A simple HTTP serve task for the Boot build tool
62 stars 34 forks source link

Unable to pass a function written in built.boot to :not-found #66

Open kennyjwilli opened 7 years ago

kennyjwilli commented 7 years ago

If my :not-found handler function is written in my build.boot file then I will get the below error:

java.lang.Thread.run                  Thread.java:  745
         java.util.concurrent.ThreadPoolExecutor$Worker.run      ThreadPoolExecutor.java:  617
          java.util.concurrent.ThreadPoolExecutor.runWorker      ThreadPoolExecutor.java: 1142
                        java.util.concurrent.FutureTask.run              FutureTask.java:  266
                                                        ...                                   
                        clojure.core/binding-conveyor-fn/fn                     core.clj: 2027
                                          boot.core/boot/fn                     core.clj: 1029
                                        boot.core/run-tasks                     core.clj: 1019
                        pandeiro.boot-http/eval902/fn/fn/fn                boot_http.clj:  112
                                         clojure.core/deref                     core.clj: 2317
                                                        ...                                   
                           pandeiro.boot-http/eval902/fn/fn                boot_http.clj:   77
                                          boot.pod/eval-in*                      pod.clj:  471
                                                        ...                                   
org.projectodd.shimdandy.impl.ClojureRuntimeShimImpl.invoke  ClojureRuntimeShimImpl.java:  102
org.projectodd.shimdandy.impl.ClojureRuntimeShimImpl.invoke  ClojureRuntimeShimImpl.java:  109
                                                        ...                                   
                                          boot.pod/eval-in*                      pod.clj:  468
                                          clojure.core/eval                     core.clj: 3194
                                                        ...                                   
                             pandeiro.boot-http.impl/server                     impl.clj:  142
                       pandeiro.boot-http.impl/ring-handler                     impl.clj:  118
                        pandeiro.boot-http.impl/dir-handler                     impl.clj:   90
                     pandeiro.boot-http.impl/wrap-not-found                     impl.clj:   82
                        pandeiro.boot-http.util/resolve-sym                     util.clj:    4
                                        clojure.core/symbol                     core.clj:  579
                                                        ...                                   
         java.lang.NullPointerException: 
clojure.lang.Compiler$CompilerException: java.lang.NullPointerException, compiling:(NO_SOURCE_FILE:0:0)
             clojure.lang.ExceptionInfo: java.lang.NullPointerException, compiling:(NO_SOURCE_FILE:0:0)
    file: "/tmp/boot.user7518152912469497163.clj"
    line: 35

Here is my example task I am calling:

(defn not-found-handler
  [req]
  {:status  404
   :headers {}
   :body    "Not found"})

(deftask start-server
         []
         (comp
           (serve :not-found 'not-found-handler)
           (wait)))

Not quite sure what the cause of this error is. It must be something boot specific. If I move my handler into a clj file in my project, then it works correctly - no error thrown. Example:

(ns myns.core)

(defn not-found-handler
  [req]
  {:status  404
   :headers {}
   :body    "Not found"})
;; build.boot
(require '[myns.core :as core])

(deftask start-server
         []
         (comp
           (serve :not-found 'core/not-found-handler)
           (wait)))
pandeiro commented 7 years ago

The symbol needs to be fully qualified with its namespace included, and that var that it points to must be able to be resolved from a namespace loaded from the classpath (which, in boot, would include your :source-paths directories, but not build.boot). So this is a limitation of boot. (Maybe we need to spell this out in the README?)

kennyjwilli commented 7 years ago

I could've sworn I have passed a symbol declared in my build.boot to a task, but maybe I'm crazy. Though, boot-http executes in a pod, which is likely different than the scenario I am recalling.

I think it'd be helpful to have a note in the README.