Add minimal error handling

This commit is contained in:
Scott Richmond 2022-05-26 18:39:37 -04:00
parent 7beca7e0f6
commit 8f1701dabb

View File

@ -1,12 +1,16 @@
(ns ludus.loader
(:require [babashka.fs :as fs]))
(:require [babashka.fs :as fs]))
(defn cwd [] (fs/cwd))
(defn load-import
([file] (-> file (fs/canonicalize) (fs/file) (slurp)))
([file from]
(load-import
(fs/path
(fs/parent (fs/canonicalize from))
(fs/path file)))))
([file]
(let [path (-> file (fs/canonicalize) (fs/file))]
(try (slurp path)
(catch java.io.FileNotFoundException _
(throw (ex-info (str "File " path " not found") {:path path ::error true}))))))
([file from]
(load-import
(fs/path
(fs/parent (fs/canonicalize from))
(fs/path file)))))