Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed NullPointerException and made tests run #112

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fmw
Copy link

@fmw fmw commented Mar 21, 2015

When integrating Sidecar into my project I ran into some NullPointerExceptions. I wrote a quick fix, which isn't as thorough as it could be, because it fixes the symptom (i.e. the exceptions went away), but doesn't address the root cause (i.e. the atoms not being provided to the relevant functions). Apart from the atom? check, I also threw away some broken tests and a duplicate function (norm-path) in order to make the tests run again.

Thanks for the great work on Figwheel and Sidecar! I hope this fix saves someone some time.

@fmw
Copy link
Author

fmw commented Mar 25, 2015

Here is some context about the issue I was experiencing before my fix:

server=> (start-figwheel)
Starting figwheel
Figwheel: Starting server at http://localhost:3449
{:break-loop-ch #<ManyToManyChannel clojure.core.async.impl.channels.ManyToManyChannel@5dce8de>, :builds [{:source-paths ["env/dev/cljs" "src/cljs"], :id "dev", :compiler {:output-dir "resources/public/js/out", :optimizations :none, :source-map-path "resources/public/js/", :output-to "resources/public/js/app.js", :source-map-timestamp true, :asset-path "js/out", :source-map "resources/public/js/source.map", :main hermes.dev, :pretty-print true}}], :builder #<auto$before$fn__7381 clojurescript_build.auto$before$fn__7381@3159838f>, :each-iteration-hook #<auto_builder$autobuild_STAR_$fn__7576 figwheel_sidecar.auto_builder$autobuild_STAR_$fn__7576@556fd4c4>}
server=> Compiling "resources/public/js/app.js" from ["env/dev/cljs" "src/cljs"]...
Successfully compiled "resources/public/js/app.js" in 8.627 seconds.
Compiling "resources/public/js/app.js" failed.
java.lang.NullPointerException: null
 at clojure.core$swap_BANG_.invoke (core.clj:2233)
    figwheel_sidecar.core$send_message_BANG_.invoke (core.clj:146)
    figwheel_sidecar.core$send_changed_files.invoke (core.clj:152)
    figwheel_sidecar.core$notify_cljs_ns_changes.invoke (core.clj:352)
    figwheel_sidecar.core$check_for_changes.invoke (core.clj:376)
    figwheel_sidecar.auto_builder$check_changes.invoke (auto_builder.clj:43)
    clojure.lang.AFn.applyToHelper (AFn.java:156)
    clojure.lang.AFn.applyTo (AFn.java:144)
    clojure.core$apply.invoke (core.clj:626)
    clojure.core$partial$fn__4228.doInvoke (core.clj:2468)
    clojure.lang.RestFn.invoke (RestFn.java:408)
    clojurescript_build.auto$after$fn__7384.invoke (auto.clj:65)
    clojurescript_build.auto$after$fn__7384.invoke (auto.clj:64)
    clojurescript_build.auto$error$fn__7387.invoke (auto.clj:71)
    clojurescript_build.auto$before$fn__7381.invoke (auto.clj:60)
    clojurescript_build.auto$make_conditional_builder$fn__7399.invoke (auto.clj:103)
    clojure.core$mapv$fn__6311.invoke (core.clj:6353)
    clojure.lang.ArrayChunk.reduce (ArrayChunk.java:58)
    clojure.core.protocols/fn (protocols.clj:98)
    clojure.core.protocols$fn__6057$G__6052__6066.invoke (protocols.clj:19)
    clojure.core.protocols$seq_reduce.invoke (protocols.clj:31)
    clojure.core.protocols/fn (protocols.clj:60)
    clojure.core.protocols$fn__6031$G__6026__6044.invoke (protocols.clj:13)
    clojure.core$reduce.invoke (core.clj:6289)
    clojure.core$mapv.invoke (core.clj:6353)
    clojurescript_build.auto$autobuild_STAR_$fn__7485$state_machine__9362__auto____7486$fn__7491.invoke (auto.clj:186)
    clojurescript_build.auto$autobuild_STAR_$fn__7485$state_machine__9362__auto____7486.invoke (auto.clj:177)
    clojure.core.async.impl.ioc_macros$run_state_machine.invoke (ioc_macros.clj:940)
    clojure.core.async.impl.ioc_macros$run_state_machine_wrapped.invoke (ioc_macros.clj:944)
    clojure.core.async$ioc_alts_BANG_$fn__9527.invoke (async.clj:362)
Exception in thread "async-dispatch-3" java.lang.NullPointerException
    at clojure.core$swap_BANG_.invoke(core.clj:2233)
    at figwheel_sidecar.core$send_message_BANG_.invoke(core.clj:146)
    at figwheel_sidecar.core$compile_error_occured.invoke(core.clj:420)
    at figwheel_sidecar.auto_builder$handle_exceptions.invoke(auto_builder.clj:54)
    at clojure.lang.AFn.applyToHelper(AFn.java:156)
    at clojure.lang.AFn.applyTo(AFn.java:144)
    at clojure.core$apply.invoke(core.clj:626)
    at clojure.core$partial$fn__4228.doInvoke(core.clj:2468)
    at clojure.lang.RestFn.invoke(RestFn.java:408)
    at clojurescript_build.auto$error$fn__7387.invoke(auto.clj:73)
    at clojurescript_build.auto$before$fn__7381.invoke(auto.clj:60)
    at clojurescript_build.auto$make_conditional_builder$fn__7399.invoke(auto.clj:103)
    at clojure.core$mapv$fn__6311.invoke(core.clj:6353)
    at clojure.lang.ArrayChunk.reduce(ArrayChunk.java:58)
    at clojure.core.protocols$fn__6093.invoke(protocols.clj:98)
    at clojure.core.protocols$fn__6057$G__6052__6066.invoke(protocols.clj:19)
    at clojure.core.protocols$seq_reduce.invoke(protocols.clj:31)
    at clojure.core.protocols$fn__6076.invoke(protocols.clj:60)
    at clojure.core.protocols$fn__6031$G__6026__6044.invoke(protocols.clj:13)
    at clojure.core$reduce.invoke(core.clj:6289)
    at clojure.core$mapv.invoke(core.clj:6353)
    at clojurescript_build.auto$autobuild_STAR_$fn__7485$state_machine__9362__auto____7486$fn__7491.invoke(auto.clj:186)
    at clojurescript_build.auto$autobuild_STAR_$fn__7485$state_machine__9362__auto____7486.invoke(auto.clj:177)
    at clojure.core.async.impl.ioc_macros$run_state_machine.invoke(ioc_macros.clj:940)
    at clojure.core.async.impl.ioc_macros$run_state_machine_wrapped.invoke(ioc_macros.clj:944)
    at clojure.core.async$ioc_alts_BANG_$fn__9527.invoke(async.clj:362)
    at clojure.core.async$do_alts$fn__9481$fn__9484.invoke(async.clj:231)
    at clojure.core.async.impl.channels.ManyToManyChannel$fn__5847.invoke(channels.clj:262)
    at clojure.lang.AFn.run(AFn.java:22)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)

This error occurs on Ubuntu 13.10 (and whatever version of Ubuntu I'm running at home) with the following JVM version:

java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode

This is the code that reproduces the exceptions for me:

(ns server
  (:require [clojure.tools.namespace.repl :refer (refresh)]
            [cemerick.piggieback :as piggieback]
            [weasel.repl.websocket :as weasel]
            [environ.core :refer [env]]
            [figwheel-sidecar.auto-builder :as fig-auto]
            [figwheel-sidecar.core :as fig]
            [hermes.gcs :as gcs]
            [hermes.state :as state]
            [hermes.handler :as handler]))

(defn browser-repl []
  (piggieback/cljs-repl :repl-env (weasel/repl-env :ip "0.0.0.0" :port 9001)))

;; FIX: right now, we need to use ther http-kit adapter for Sente
;; in development mode because that is what Figwheel needs, while
;; using Immutant in production-mode because it has better
;; WebSockets support. Obviously, using a single server is preferable,
;; so let's revisit this later.

(defn start-figwheel []
  (let [{:keys [bucket state-file key-file service-account-email]} env]
    (if (not-any? nil? [bucket state-file key-file service-account-email])
      (do
        (state/update-state-from-string!
         (gcs/get! (:credential @state/config) bucket state-file))
        (println "Starting figwheel")
        (let [fighwheel-server
              (fig/start-server {:http-server-root "public"
                                 :server-port 3449
                                 :css-dirs ["resources/public/css"]
                                 :ring-handler 'hermes.handler/app})
              config
              {:builds
               [{:id "dev"
                 :source-paths ["env/dev/cljs" "src/cljs"]
                 :compiler {:main 'hermes.dev
                            :asset-path "js/out"
                            :output-to "resources/public/js/app.js"
                            :output-dir "resources/public/js/out"
                            :source-map-path "resources/public/js/"
                            :source-map "resources/public/js/source.map"
                            :source-map-timestamp true
                            :optimizations :none
                            :pretty-print true}}]}]
          (fig-auto/autobuild* config)))
      (println "Can't start without the following environment variables:"
               "BUCKET, STATE_FILE, KEY_FILE, SERVICE_ACCOUNT_EMAIL"))))

@bhauman
Copy link
Owner

bhauman commented Mar 27, 2015

Sorry for not getting back to you on this. I've been a bit busy lately. I'll take a close look at this today.

@diamondo25
Copy link

👍

@bhauman
Copy link
Owner

bhauman commented Apr 11, 2015

Again sorry for taking so long.

figwheel-sidecar.auto-builder/autobuild* Takes a map with :builds and :fighweel-server you don't seem to be passing the :figwheel-server in.

@fmw
Copy link
Author

fmw commented Apr 20, 2015

Thanks for your response! Providing a :figwheel-server value does fix the problem for me, so I assume that the fix should probably be to log a warning if it isn't provided. The application does work if the server isn't passed to Figwheel, though!

@arichiardi
Copy link
Contributor

I was scanning through some issue and wondering if this is still valid and/or the fix can go in anyways.

@bhauman
Copy link
Owner

bhauman commented Jun 25, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants