diff --git a/src/main/lemondronor/circlebot.cljs b/src/main/lemondronor/circlebot.cljs index a6c9b30..983cde7 100644 --- a/src/main/lemondronor/circlebot.cljs +++ b/src/main/lemondronor/circlebot.cljs @@ -483,6 +483,9 @@ (defn build-config [config cli-config secrets] (util/deep-merge default-config config cli-config secrets)) + +(def default-config-path "config.yaml") + (defn main [& args] (-> commander (.option "--lat " "Latitude of the circle of region of interest" parse-number) @@ -493,11 +496,17 @@ (.option "--basestation-sqb " "Path to a basestation.sqb database file") (.option "--tweeting" "Enables tweeting") (.option "--no-tweeting" "Do not tweet") - (.option "--config " "Path to the configuration yaml file" "config.yaml") + (.option "--config " "Path to the configuration yaml file") (.option "--secrets " "Path to the secrets yaml file" "secrets.yaml") (.parse (.-argv js/process))) (let [start-time (current-time)] - (p/let [base-config (util/read-config (.-config commander)) + ;; If --config-path is specified, definitely try to read that + ;; file. Otherwise, only read config.yaml if it exists. + (p/let [base-config (if-let [config-path (.-config commander)] + (util/read-config config-path) + (if (fs/existsSync default-config-path) + (util/read-config default-config-path) + {})) cli-config (build-config-from-commander commander) secrets (util/read-config (.-secrets commander)) config (build-config base-config cli-config secrets) @@ -524,3 +533,10 @@ (/ (- end-time start-time) 1000) (count new-db) (count potential-circles))))))) + + +;; (.on js/process "unhandledRejection" +;; (fn [reason promise] +;; (log-error "Error: %s" (.-message reason)) +;; (println (.-stack reason)) +;; (.exit js/process 1))) diff --git a/src/main/lemondronor/circlebot/util.cljs b/src/main/lemondronor/circlebot/util.cljs index 3cf6ba4..1c4aa0a 100644 --- a/src/main/lemondronor/circlebot/util.cljs +++ b/src/main/lemondronor/circlebot/util.cljs @@ -29,10 +29,13 @@ (defn read-config [path] (log-verbose "Reading config file %s" path) - (p/let [data (read-file path {:encoding "utf-8"})] - (let [config (-> (yaml/safeLoad data) - (js->clj :keywordize-keys true))] - (or config {})))) + (p/try + (p/let [data (read-file path {:encoding "utf-8"})] + (let [config (-> (yaml/safeLoad data) + (js->clj :keywordize-keys true))] + (or config {}))) + (p/catch :default e + (throw (str "Error reading config file '" path "': " e))))) ;; Fetches a URL. Returns a promise that resolves to the body of the