Error in main using Stuart Sierra's Component when deploying to Heroku

316 views
Skip to first unread message

Rickesh Bedia

unread,
Mar 13, 2017, 12:38:36 PM3/13/17
to Clojure
I am trying to start my clojure application on my heroku dyno but I keep getting and error in my stuartsierra.component/start.

Below is my core file containing my main function.

(defrecord Listener [listener]
  component/Lifecycle
  (start [component]
    (assoc component :listener (yada/listener
                                 ["/"
                                  [(view/view-route)
                                   routes/route-handler
                                   ["public/" (new-directory-resource (io/file "target/cljsbuild/public") {})]
                                   [true (as-resource nil)]]]
                                 (or (env :port) (get (read-config "resources/config.edn" {:profile :dev}) :webserver))
                                 )))
  (stop [component]
    (when-let [close (-> component :listener :close)]
      (close))
    (assoc component :listener nil)))

(defn new-system []
  (component/system-map
    :listener (map->Listener {})
    ))

(def system nil)

(defn init []
  (alter-var-root #'system
                  (constantly (new-system))))

(defn start []
  (alter-var-root #'system component/start))

(defn stop []
  (alter-var-root #'system
                  (fn [s] (when s (component/stop s)))))

(defn go []
  (init)
  (start))

(defn reset []
  (stop)
  (refresh :after 'web.core/go))

(defn -main
  [& [port]]
  (component/start (new-system))
  (println "System Started")
  @(promise))

This is my core file with all my stuartsierra.component code. This all works perfectly when I run it locally on my laptop doing lein repl and then (go) and also when I just do lein run. So I am confused as to why it doesn't work when I push this to the heroku dyno.

The error I get is

Exception in thread "main" clojure.lang.ExceptionInfo: Error in component :listener in system com.stuartsierra.component.SystemMap calling #'com.stuartsierra.component/start {:reason :com.stuartsierra.component/component-function-threw-exception, :function #'com.stuartsierra.component/start, :system-key :listener, :component #web.core.Listener{:listener nil}, :system #<SystemMap>}, compiling:(/tmp/form-init9049917434081554913.clj:1:73)
This is telling me that my :listener is nil in the system-map. When I check locally (doing lein repl (go)) in (keys system) is (:listener) which is good so that means that the listener is starting and is in the system.

When I do (-> system :listener) I get #web.core.Listener{:listener {:port 3300, :close #object[yada.aleph$listener$fn__21671 0xa5d4865 "yada.aleph$listener$fn__21671@a5d4865"], :server #object[aleph.netty$start_server$reify__13574 0x3cc9a232 "aleph.netty$start_server$reify__13574@3cc9a232"]}} which is perfect as the port has loaded up (3300) and the server has started.

This makes it all the more confusing as to why the :listener is nil in my heroku app

Any help would be much appreciated. Thanks

James Reeves

unread,
Mar 13, 2017, 1:09:50 PM3/13/17
to clo...@googlegroups.com
Can you provide the full error message? So the cause as well as the Component ex-info wrapper?

I don't think this is anything to do with :listener being nil. I think you're looking at the Component exception and not checking the "cause" exception with .getCause.

My guess is that you're running into problems at (env :port), which will be a string, while the port in the edn configuration will probably be an integer. So it works when PORT isn't set on your local machine, but fails on Heroku where PORT is set.

- James

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rickesh Bedia

unread,
Mar 13, 2017, 1:23:44 PM3/13/17
to Clojure, ja...@booleanknot.com
The full error message is (when I look at the heroku logs)

Exception in thread "main" clojure.lang.ExceptionInfo: Error in component :listener in system com.stuartsierra.component.SystemMap calling #'com.stuartsierra.component/start {:reason :com.stuartsierra.component/component-function-threw-exception, :function #'com.stuartsierra.component/start, :system-key :listener, :component #web.core.Listener{:listener nil}, :system #<SystemMap>}, compiling:(/tmp/form-init7411312467703964054.clj:1:73)
2017-03-13T14:18:34.518986+00:00 app[web.1]: at clojure.lang.Compiler.load(Compiler.java:7391)
2017-03-13T14:18:34.519021+00:00 app[web.1]: at clojure.lang.Compiler.loadFile(Compiler.java:7317)
2017-03-13T14:18:34.519050+00:00 app[web.1]: at clojure.main$load_script.invokeStatic(main.clj:275)
2017-03-13T14:18:34.519088+00:00 app[web.1]: at clojure.main$init_opt.invokeStatic(main.clj:277)
2017-03-13T14:18:34.519125+00:00 app[web.1]: at clojure.main$init_opt.invoke(main.clj:277)
2017-03-13T14:18:34.519157+00:00 app[web.1]: at clojure.main$initialize.invokeStatic(main.clj:308)
2017-03-13T14:18:34.519190+00:00 app[web.1]: at clojure.main$null_opt.invokeStatic(main.clj:342)
2017-03-13T14:18:34.519229+00:00 app[web.1]: at clojure.main$null_opt.invoke(main.clj:339)
2017-03-13T14:18:34.519266+00:00 app[web.1]: at clojure.main$main.invokeStatic(main.clj:421)
2017-03-13T14:18:34.519300+00:00 app[web.1]: at clojure.main$main.doInvoke(main.clj:384)
2017-03-13T14:18:34.519344+00:00 app[web.1]: at clojure.lang.RestFn.invoke(RestFn.java:421)
2017-03-13T14:18:34.519372+00:00 app[web.1]: at clojure.lang.Var.invoke(Var.java:383)
2017-03-13T14:18:34.519450+00:00 app[web.1]: at clojure.lang.AFn.applyToHelper(AFn.java:156)
2017-03-13T14:18:34.632589+00:00 heroku[web.1]: Process exited with status 1
2017-03-13T14:18:34.519503+00:00 app[web.1]: at clojure.lang.Var.applyTo(Var.java:700)
2017-03-13T14:18:34.519564+00:00 app[web.1]: at clojure.main.main(main.java:37)
2017-03-13T14:18:34.519947+00:00 app[web.1]: Caused by: clojure.lang.ExceptionInfo: Error in component :listener in system com.stuartsierra.component.SystemMap calling #'com.stuartsierra.component/start {:reason :com.stuartsierra.component/component-function-threw-exception, :function #'com.stuartsierra.component/start, :system-key :listener, :component #web.core.Listener{:listener nil}, :system #<SystemMap>}
2017-03-13T14:18:34.520007+00:00 app[web.1]: at clojure.core$ex_info.invokeStatic(core.clj:4617)
2017-03-13T14:18:34.520035+00:00 app[web.1]: at clojure.core$ex_info.invoke(core.clj:4617)
2017-03-13T14:18:34.520098+00:00 app[web.1]: at com.stuartsierra.component$try_action.invokeStatic(component.cljc:119)
2017-03-13T14:18:34.520153+00:00 app[web.1]: at com.stuartsierra.component$try_action.invoke(component.cljc:116)
2017-03-13T14:18:34.520215+00:00 app[web.1]: at com.stuartsierra.component$update_system$fn__27520.invoke(component.cljc:139)
2017-03-13T14:18:34.520267+00:00 app[web.1]: at clojure.lang.ArraySeq.reduce(ArraySeq.java:109)
2017-03-13T14:18:34.520327+00:00 app[web.1]: at clojure.core$reduce.invokeStatic(core.clj:6544)
2017-03-13T14:18:34.520377+00:00 app[web.1]: at clojure.core$reduce.invoke(core.clj:6527)
2017-03-13T14:18:34.520400+00:00 app[web.1]: at com.stuartsierra.component$update_system.invokeStatic(component.cljc:135)
2017-03-13T14:18:34.520430+00:00 app[web.1]: at com.stuartsierra.component$update_system.doInvoke(component.cljc:129)
2017-03-13T14:18:34.520458+00:00 app[web.1]: at clojure.lang.RestFn.invoke(RestFn.java:445)
2017-03-13T14:18:34.520536+00:00 app[web.1]: at com.stuartsierra.component$start_system.invokeStatic(component.cljc:163)
2017-03-13T14:18:34.520610+00:00 app[web.1]: at com.stuartsierra.component$start_system.invoke(component.cljc:155)
2017-03-13T14:18:34.520729+00:00 app[web.1]: at com.stuartsierra.component$start_system.invokeStatic(component.cljc:161)
2017-03-13T14:18:34.520800+00:00 app[web.1]: at com.stuartsierra.component$start_system.invoke(component.cljc:155)
2017-03-13T14:18:34.520855+00:00 app[web.1]: at com.stuartsierra.component.SystemMap.start(component.cljc:178)
2017-03-13T14:18:34.520969+00:00 app[web.1]: at web.core$_main.invokeStatic(core.clj:71)
2017-03-13T14:18:34.521016+00:00 app[web.1]: at web.core$_main.doInvoke(core.clj:69)
2017-03-13T14:18:34.521069+00:00 app[web.1]: at clojure.lang.RestFn.invoke(RestFn.java:397)
2017-03-13T14:18:34.521135+00:00 app[web.1]: at clojure.lang.Var.invoke(Var.java:375)
2017-03-13T14:18:34.521191+00:00 app[web.1]: at user$eval5.invokeStatic(form-init7411312467703964054.clj:1)
2017-03-13T14:18:34.521250+00:00 app[web.1]: at user$eval5.invoke(form-init7411312467703964054.clj:1)
2017-03-13T14:18:34.521308+00:00 app[web.1]: at clojure.lang.Compiler.eval(Compiler.java:6927)
2017-03-13T14:18:34.521366+00:00 app[web.1]: at clojure.lang.Compiler.eval(Compiler.java:6917)
2017-03-13T14:18:34.521435+00:00 app[web.1]: at clojure.lang.Compiler.load(Compiler.java:7379)
2017-03-13T14:18:34.521530+00:00 app[web.1]: ... 14 more
2017-03-13T14:18:34.521743+00:00 app[web.1]: Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.IPersistentCollection
2017-03-13T14:18:34.521785+00:00 app[web.1]: at clojure.core$conj__4345.invokeStatic(core.clj:82)
2017-03-13T14:18:34.521814+00:00 app[web.1]: at clojure.core$merge$fn__4877.invoke(core.clj:2940)
2017-03-13T14:18:34.521851+00:00 app[web.1]: at clojure.core$reduce1.invokeStatic(core.clj:925)
2017-03-13T14:18:34.521885+00:00 app[web.1]: at clojure.core$reduce1.invokeStatic(core.clj:915)
2017-03-13T14:18:34.521922+00:00 app[web.1]: at clojure.core$merge.invokeStatic(core.clj:2939)
2017-03-13T14:18:34.521955+00:00 app[web.1]: at clojure.core$merge.doInvoke(core.clj:2932)
2017-03-13T14:18:34.521988+00:00 app[web.1]: at clojure.lang.RestFn.invoke(RestFn.java:421)
2017-03-13T14:18:34.522026+00:00 app[web.1]: at yada.aleph$listener.invokeStatic(aleph.clj:15)
2017-03-13T14:18:34.522048+00:00 app[web.1]: at yada.aleph$listener.doInvoke(aleph.clj:8)
2017-03-13T14:18:34.522076+00:00 app[web.1]: at clojure.lang.RestFn.invoke(RestFn.java:423)
2017-03-13T14:18:34.522103+00:00 app[web.1]: at web.core.Listener.start(core.clj:29)
2017-03-13T14:18:34.522131+00:00 app[web.1]: at com.stuartsierra.component$eval27461$fn__27462$G__27451__27464.invoke(component.cljc:5)
2017-03-13T14:18:34.522169+00:00 app[web.1]: at com.stuartsierra.component$eval27461$fn__27462$G__27450__27467.invoke(component.cljc:5)
2017-03-13T14:18:34.522203+00:00 app[web.1]: at clojure.lang.Var.invoke(Var.java:379)
2017-03-13T14:18:34.522224+00:00 app[web.1]: at clojure.lang.AFn.applyToHelper(AFn.java:154)
2017-03-13T14:18:34.522252+00:00 app[web.1]: at clojure.lang.Var.applyTo(Var.java:700)
2017-03-13T14:18:34.522302+00:00 app[web.1]: at clojure.core$apply.invokeStatic(core.clj:648)
2017-03-13T14:18:34.522386+00:00 app[web.1]: at clojure.core$apply.invoke(core.clj:641)
2017-03-13T14:18:34.522493+00:00 app[web.1]: at com.stuartsierra.component$try_action.invokeStatic(component.cljc:117)
2017-03-13T14:18:34.522562+00:00 app[web.1]: ... 36 more
2017-03-13T14:18:34.643501+00:00 heroku[web.1]: State changed from starting to crashed

I think you may be right about (:env port) as there is the error "Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.IPersistentCollection"

How would I solve this? Thanks

Kevin Downey

unread,
Mar 13, 2017, 1:37:34 PM3/13/17
to clo...@googlegroups.com
On 03/13/2017 09:38 AM, 'Rickesh Bedia' via Clojure wrote:
> I am trying to start my clojure application on my heroku dyno but I keep
> getting and error in my stuartsierra.component/start.
>
> Below is my core file containing my main function.
>
> (defrecord Listener [listener]
> component/Lifecycle
> (start [component]
> (assoc component :listener (yada/listener
> ["/"
> [(view/view-route)
> routes/route-handler
> ["public/" (new-directory-resource
> (io/file "target/cljsbuild/public") {})]
> [true (as-resource nil)]]]
> (or (env :port) (get (read-config
> "resources/config.edn" {:profile :dev}) :webserver))

resources/config.edn is likely incorrect, depending on how you are
running your app. The "resources/" directory is typically on the
classpath, so you refer a file in it as just "config.edn". Referring to
it as "resources/config.edn" is the kind of thing that will work
sometimes at the repl, but depending on how you are packaging and
deploying you app will fail.

The file business with target/ is also something that is likely to fail.

I am not familiar with how heroku deploys clojure, but it looks like
they build an uberjar and run that, so if you want to see how your code
will work there run `lein uberjar` then `java -jar your-uberjar.jar`.
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to clojure+u...@googlegroups.com
> <mailto:clojure+u...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.


--
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?
Reply all
Reply to author
Forward
0 new messages