Skip to content

Commit

Permalink
add fallback when the shadow-cljs CLI fails to connect
Browse files Browse the repository at this point in the history
if the server is dead but didn't clean up its files it should
just continue starting a new process instead of doing nothing.
  • Loading branch information
thheller committed Mar 23, 2018
1 parent db4f685 commit 5b376d4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
22 changes: 14 additions & 8 deletions src/main/shadow/cljs/npm/cli.cljs
Expand Up @@ -601,6 +601,17 @@
false
)))))

(defn do-start [project-root config args opts]
(cond
(:deps config)
(run-clojure project-root config args opts)

(:lein config)
(run-lein project-root config args opts)

:else
(run-standalone project-root config args opts)))

(defn ^:export main [args]

;; https://github.com/tapjs/signal-exit
Expand Down Expand Up @@ -686,16 +697,11 @@
(server-start project-root config args opts))

server-running?
(client/run project-root config server-port-file opts args)

(:deps config)
(run-clojure project-root config args opts)

(:lein config)
(run-lein project-root config args opts)
(client/run project-root config server-port-file opts args
#(do-start project-root config args opts))

:else
(run-standalone project-root config args opts)
(do-start project-root config args opts)
))))))))
(catch :default ex
(print-error ex)
Expand Down
8 changes: 5 additions & 3 deletions src/main/shadow/cljs/npm/client.cljs
Expand Up @@ -166,7 +166,9 @@
(js/process.stdin.removeListener "close" stop!)
))))

(defn run [project-root config server-port-file opts args]
(defn run
"attempts to connect to running server. if the connect fails calls callback"
[project-root config server-port-file opts args fallback]
(let [cli-repl
(-> (util/slurp server-port-file)
(js/parseInt 10))]
Expand All @@ -190,6 +192,6 @@
(.on socket "error"
(fn [err]
(println "shadow-cljs - socket connect failed, server process dead?")
(js/process.exit 1)))
))))
(fallback err)
))))))

0 comments on commit 5b376d4

Please sign in to comment.