Skip to content

Commit

Permalink
asserterror catching
Browse files Browse the repository at this point in the history
  • Loading branch information
awb99 committed Jun 21, 2024
1 parent 54dfb12 commit f952c1d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lib/algo/src/ta/algo/spec/type/bar_strategy.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
[ta.algo.env.core :refer [get-trailing-bars]]
[ta.algo.error-report :refer [save-error-report]]))

(defn create-error [spec ex]
(let [filename (save-error-report (str "run-algo-" (:algo spec)) spec ex)]
(error "run-algo " spec " exception. details: " filename)
(nom/fail ::algo-calc {:message "algo calc exception!"
:location :bar-strategy-algo
:file filename
:spec spec
;:ds-bars ds-bars ; dataset cannot be sent to the browser.
})))

(defn run-algo-safe [algo-fn env spec ds-bars]
(warn "run-algo-safe: " (:algo spec))
(cond
Expand All @@ -25,15 +35,8 @@
(try
(warn "run-algo-safe else.. fn: " algo-fn)
(algo-fn env spec ds-bars)
(catch Exception ex
(let [filename (save-error-report (str "run-algo-" (:algo spec)) spec ex)]
(error "run-algo " spec " exception. details: " filename)
(nom/fail ::algo-calc {:message "algo calc exception!"
:location :bar-strategy-algo
:file filename
:spec spec
;:ds-bars ds-bars ; dataset cannot be sent to the browser.
}))))))
(catch AssertionError ex (create-error spec ex))
(catch Exception ex (create-error spec ex)))))

(defn create-trailing-bar-loader [{:keys [asset calendar trailing-n] :as spec}]
(cond
Expand Down
2 changes: 2 additions & 0 deletions lib/engine/src/ta/engine/javelin/cell.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
(warn "calculating formula args: " args)
(try
(apply formula-fn args)
(catch AssertionError ex
(nom/fail ::error {:message "algo assert failure"}))
(catch Exception ex
(nom/fail ::error {:message "algo exception"})))))

Expand Down
7 changes: 7 additions & 0 deletions lib/import/src/ta/db/bars/dynamic/import.clj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
(nom/fail ::get-bars-safe {:message "import-provider has returned nil."
:opts opts
:task task})))
(catch AssertionError ex
(nom/fail ::get-bars-safe {:message "import-provider get-bars has thrown an assertion error"
:opts opts
:task task}))
(catch Exception ex
(nom/fail ::get-bars-safe {:message "import-provider get-bars has thrown an exception"
:opts opts
Expand All @@ -53,6 +57,9 @@
(info "dynamically received ds-bars! appending to db...")
(b/append-bars (:bar-db state) opts bar-ds)
(overview/update-range (:overview-db state) opts (:db task)))
(catch AssertionError ex
(error "dynamic-import.append-bars exception! asset: " (:asset opts) "calendar: " (:calendar opts))
nil)
(catch Exception ex
(error "dynamic-import.append-bars exception! asset: " (:asset opts) "calendar: " (:calendar opts))
nil)))
Expand Down

0 comments on commit f952c1d

Please sign in to comment.