Skip to content

Commit f582f26

Browse files
author
dnolen
committed
add some basic error handling
1 parent fcef304 commit f582f26

File tree

1 file changed

+42
-5
lines changed

1 file changed

+42
-5
lines changed

src/main/clojure/cljs/cli.clj

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,50 @@ present"
248248
`(~'ns ~'cljs.user))
249249
(repl/run-inits renv inits)
250250
(when script
251-
(if (= "-" script)
251+
(cond
252+
(= "-" script)
252253
(repl/load-stream renv "<cljs repl>" *in*)
253-
(repl/load-file renv script)))
254+
255+
(.exists (io/file script))
256+
(repl/load-file renv script)
257+
258+
(string/starts-with? script "@")
259+
(if-let [rsrc (io/resource (subs script 1))]
260+
(repl/load-file renv rsrc)
261+
(throw
262+
(ex-info
263+
(str "Resource script " (subs script 1) " does not exist")
264+
{:cljs.main/error :invalid-arg})))
265+
266+
(string/starts-with? script "@/")
267+
(if-let [rsrc (io/resource (subs script 2))]
268+
(repl/load-file renv rsrc)
269+
(throw
270+
(ex-info
271+
(str "Resource script " (subs script 2) " does not exist")
272+
{:cljs.main/error :invalid-arg})))
273+
274+
(string/starts-with? script "-")
275+
(throw
276+
(ex-info
277+
(str "Expected script or -, got flag " script " instead")
278+
{:cljs.main/error :invalid-arg}))
279+
280+
:else
281+
(throw
282+
(ex-info
283+
(str "Script " script " does not exist")
284+
{:cljs.main/error :invalid-arg}))))
254285
(when main
255-
(repl/load-file renv (build/ns->source main))
256-
(repl/evaluate-form renv (ana-api/empty-env) "<cljs repl>"
257-
`(~(symbol (name main) "-main") ~@args)))
286+
(let [src (build/ns->source main)]
287+
(when-not (io/resource src)
288+
(throw
289+
(ex-info
290+
(str "Namespace " main " does not exist")
291+
{:cljs.main/error :invalid-arg})))
292+
(repl/load-file renv src)
293+
(repl/evaluate-form renv (ana-api/empty-env) "<cljs repl>"
294+
`(~(symbol (name main) "-main") ~@args))))
258295
(repl/tear-down renv)))))))
259296

260297
(defn- main-opt

0 commit comments

Comments
 (0)