Skip to content

Commit

Permalink
Fix NPE in builder/build-static-app! when there's nothing to build, c…
Browse files Browse the repository at this point in the history
…loses #339
  • Loading branch information
mk committed Dec 15, 2022
1 parent eb62d4c commit 43c02b1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/nextjournal/clerk/builder.clj
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,16 @@
:bundle? false
:browse? false
:report-fn (if @webserver/!server build-ui-reporter stdout-reporter)}
(let [opts' (cond-> opts
index (assoc :index (str index)))
expanded-paths (when expand-paths? (expand-paths opts'))]
(let [opts+index (cond-> opts
index (assoc :index (str index)))
{:as opts' :keys [expanded-paths]} (cond-> opts+index
expand-paths? (merge (try {:expanded-paths (expand-paths opts+index)}
(catch Exception e
{:error e}))))]
(-> opts'
(update :resource->url #(merge {} %2 %1) @config/!resource->url)
(cond->
(cond-> #_opts'
expand-paths? (dissoc :expand-paths?)
expanded-paths (assoc :expanded-paths expanded-paths)
(and (not index) (= 1 (count expanded-paths))) (assoc :index (first expanded-paths)))))))

#_(process-build-opts {:index 'book.clj :expand-paths? true})
Expand Down
6 changes: 6 additions & 0 deletions test/nextjournal/clerk/builder_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,18 @@
(builder/expand-paths {:paths-fn 'clojure.core/non-existant-var})))
(is (thrown-with-msg? ExceptionInfo #"must be a qualified symbol pointing at an existing var"
(builder/expand-paths {:paths-fn "hi"})))
(is (thrown-with-msg? ExceptionInfo #"nothing to build"
(builder/expand-paths {:paths []})))
(is (thrown-with-msg? ExceptionInfo #"An error occured invoking"
(builder/expand-paths {:paths-fn 'clojure.core/inc})))
(is (thrown-with-msg? ExceptionInfo #"`:paths-fn` must compute sequential value"
(builder/expand-paths {:paths-fn 'clojure.core/+})))
(is (thrown? ExceptionInfo (builder/expand-paths {:index ["book.clj"]})))))

(deftest build-static-app!
(testing "error when paths are empty (issue #339)"
(is (thrown-with-msg? ExceptionInfo #"nothing to build" (builder/build-static-app! {:paths []})))))

(deftest process-build-opts
(testing "assigns index when only one path is given"
(is (= (str (fs/file "notebooks" "rule_30.clj"))
Expand Down

0 comments on commit 43c02b1

Please sign in to comment.