Skip to content

Commit 95ab741

Browse files
author
dnolen
committed
CLJS-2572: cljs.main: throw from -i script doesn't terminate execution
1 parent 94b8dd0 commit 95ab741

2 files changed

Lines changed: 59 additions & 54 deletions

File tree

src/main/cljs/cljs/main.clj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,7 @@
5757
args)
5858
[js-args args] ((juxt #(take 2 %) #(drop 2 %)) post)
5959
repl-opt (get-js-opt js-args)]
60-
(apply cli/main repl-opt (concat pre args))
61-
(shutdown-agents)))
60+
(try
61+
(apply cli/main repl-opt (concat pre args))
62+
(finally
63+
(shutdown-agents)))))

src/main/clojure/cljs/cli.clj

Lines changed: 55 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -269,64 +269,67 @@ present"
269269
(util/debug-prn "Compiler options:" (pr-str repl/*repl-opts*)))
270270
(comp/with-core-cljs repl/*repl-opts*
271271
(fn []
272-
(repl/setup renv repl/*repl-opts*)
273-
;; REPLs don't normally load cljs_deps.js
274-
(when (and coptsf (.exists coptsf))
275-
(let [depsf (io/file (:output-dir options) "cljs_deps.js")]
276-
(when (.exists depsf)
277-
(repl/evaluate renv "cljs_deps.js" 1 (slurp depsf)))))
278-
(repl/evaluate-form renv (ana-api/empty-env) "<cljs repl>"
279-
(when-not (empty? args)
280-
`(set! *command-line-args* (list ~@args))))
281-
(repl/evaluate-form renv (ana-api/empty-env) "<cljs repl>"
282-
`(~'ns ~'cljs.user))
283-
(repl/run-inits renv inits)
284-
(when script
285-
(cond
286-
(= "-" script)
287-
(repl/load-stream renv "<cljs repl>" *in*)
288-
289-
(.exists (io/file script))
290-
(repl/load-file renv script)
291-
292-
(string/starts-with? script "@/")
293-
(if-let [rsrc (io/resource (subs script 2))]
294-
(repl/load-stream renv (util/get-name rsrc) rsrc)
295-
(throw
296-
(ex-info
297-
(str "Resource script " (subs script 2) " does not exist")
298-
{:cljs.main/error :invalid-arg})))
272+
(try
273+
(repl/setup renv repl/*repl-opts*)
274+
;; REPLs don't normally load cljs_deps.js
275+
(when (and coptsf (.exists coptsf))
276+
(let [depsf (io/file (:output-dir options) "cljs_deps.js")]
277+
(when (.exists depsf)
278+
(repl/evaluate renv "cljs_deps.js" 1 (slurp depsf)))))
279+
(repl/evaluate-form renv (ana-api/empty-env) "<cljs repl>"
280+
(when-not (empty? args)
281+
`(set! *command-line-args* (list ~@args))))
282+
(repl/evaluate-form renv (ana-api/empty-env) "<cljs repl>"
283+
`(~'ns ~'cljs.user))
284+
(repl/run-inits renv inits)
285+
(when script
286+
(cond
287+
(= "-" script)
288+
(repl/load-stream renv "<cljs repl>" *in*)
289+
290+
(.exists (io/file script))
291+
(repl/load-file renv script)
292+
293+
(string/starts-with? script "@/")
294+
(if-let [rsrc (io/resource (subs script 2))]
295+
(repl/load-stream renv (util/get-name rsrc) rsrc)
296+
(throw
297+
(ex-info
298+
(str "Resource script " (subs script 2) " does not exist")
299+
{:cljs.main/error :invalid-arg})))
299300

300-
(string/starts-with? script "@")
301-
(if-let [rsrc (io/resource (subs script 1))]
302-
(repl/load-stream renv (util/get-name rsrc) rsrc)
301+
(string/starts-with? script "@")
302+
(if-let [rsrc (io/resource (subs script 1))]
303+
(repl/load-stream renv (util/get-name rsrc) rsrc)
304+
(throw
305+
(ex-info
306+
(str "Resource script " (subs script 1) " does not exist")
307+
{:cljs.main/error :invalid-arg})))
308+
309+
(string/starts-with? script "-")
303310
(throw
304311
(ex-info
305-
(str "Resource script " (subs script 1) " does not exist")
306-
{:cljs.main/error :invalid-arg})))
307-
308-
(string/starts-with? script "-")
309-
(throw
310-
(ex-info
311-
(str "Expected script or -, got flag " script " instead")
312-
{:cljs.main/error :invalid-arg}))
312+
(str "Expected script or -, got flag " script " instead")
313+
{:cljs.main/error :invalid-arg}))
313314

314-
:else
315-
(throw
316-
(ex-info
317-
(str "Script " script " does not exist")
318-
{:cljs.main/error :invalid-arg}))))
319-
(when main
320-
(let [src (build/ns->source main)]
321-
(when-not (io/resource src)
315+
:else
322316
(throw
323317
(ex-info
324-
(str "Namespace " main " does not exist")
325-
{:cljs.main/error :invalid-arg})))
326-
(repl/load-stream renv (util/get-name src) src)
327-
(repl/evaluate-form renv (ana-api/empty-env) "<cljs repl>"
328-
`(~(symbol (name main) "-main") ~@args))))
329-
(repl/tear-down renv)))))))
318+
(str "Script " script " does not exist")
319+
{:cljs.main/error :invalid-arg}))))
320+
(when main
321+
(let [src (build/ns->source main)]
322+
(when-not (io/resource src)
323+
(throw
324+
(ex-info
325+
(str "Namespace " main " does not exist")
326+
{:cljs.main/error :invalid-arg})))
327+
(repl/load-stream renv (util/get-name src) src)
328+
(repl/evaluate-form renv (ana-api/empty-env) "<cljs repl>"
329+
`(~(symbol (name main) "-main") ~@args))))
330+
(finally
331+
(util/debug-prn "Tearing down")
332+
(repl/tear-down renv)))))))))
330333

331334
(defn- main-opt
332335
"Call the -main function from a namespace with string arguments from

0 commit comments

Comments
 (0)