Add import error handling

This commit is contained in:
Scott Richmond 2022-05-26 18:40:26 -04:00
parent 8f1701dabb
commit a5b1763324

View File

@ -340,12 +340,13 @@
name (:name ast)] name (:name ast)]
(if (contains? @ctx name) (if (contains? @ctx name)
(throw (ex-info (str "Name " name " is alrady bound") {:ast ast})) (throw (ex-info (str "Name " name " is alrady bound") {:ast ast}))
(let [result ;; TODO: add any error handling at all (let [source (try
(-> path (loader/load-import path (resolve-word ::file ctx))
(loader/load-import (resolve-word ::file ctx)) (catch Exception e
(scanner/scan) (if (::loader/error (ex-data e))
(parser/parse) (throw (ex-info (ex-message e) {:ast ast}))
(interpret path))] (throw e))))
result (-> source (scanner/scan) (parser/parse) (interpret path))]
(vswap! ctx update-ctx {name result}) (vswap! ctx update-ctx {name result})
result ;; TODO: test this! result ;; TODO: test this!
)))) ))))
@ -518,9 +519,9 @@
(interpret-ast (::parser/ast parsed) {::file file}) (interpret-ast (::parser/ast parsed) {::file file})
(catch clojure.lang.ExceptionInfo e (catch clojure.lang.ExceptionInfo e
(println "Ludus panicked in" file) (println "Ludus panicked in" file)
(println "On line" (get-in e [:ast :token ::token/line])) (println "On line" (get-in (ex-data e) [:ast :token ::token/line]))
(println (ex-message e)) (println (ex-message e))
(pp/pprint (ex-data e)) ;;(pp/pprint (ex-data e))
(System/exit 67)))) (System/exit 67))))
(defn interpret-safe [parsed] (defn interpret-safe [parsed]
@ -532,7 +533,7 @@
(println (ex-message e)) (println (ex-message e))
(pp/pprint (ex-data e))))) (pp/pprint (ex-data e)))))
(do (comment
(def source "panic! :oops (def source "panic! :oops