I’m having trouble with a null pointer compiler error in my cljs app on the following let block:
refresh-time (or (get-in db [:app :config :features :list :refresh-interval]) 15000)
refresh-duration (t/new-duration (/ (js/parseInt refresh-time) 1000) :seconds)t is juxt’s tick. Any clues?
if I replace the (/ (js/parseInt refresh-time) 1000) with a static number, no problem at all
if I leave it: 68 | (reg-event-fx 69 | work-list-refresh 70 | (fn-traced [{:keys [db]} [ ]] ---------^---------------------------------------------------------------------- null NullPointerException:
Can you provide the full code for that event handler? You describe the location as one place but the error points at a completely different place so absolutely no clue what's going on.
sure thing
You have to make sure refresh-time isn't nil or "". js/parseInt won't enjoy a nil or blank? value
The NPE is during compilation, not run time.
yeah the db values referenced are set by the init-db event that runs first or near first
right, sorry, was too quick
Also, try replacing fn-traced with plain fn.
fn-traced is clearly a macro that can do whatever. The NPE points to it, so I assume the macro is trying to rewrite the code in some way and maybe it doesn't like js/parseInt for some reason (probably because js is not an alias or a namespace, as it would have to be in CLJ).
(reg-event-fx
::work-list-refresh
(fn-traced [{:keys [db]} [_ _]]
(let [log-refresh (get-in db [ :config :features :work-list :log-refresh])
last-updated (or (t/instant (get-in db [ :modules :work-list :last-updated])) (t/instant (t/now)))
engagements? (get-in db [ :config :features :engagements :enabled])
refresh-time (get-in db [ :config :features :work-list :refresh-interval])
refresh-duration (t/new-duration (/ refresh-time 1000) :seconds)
index (or (get-in db [ :modules :work-list :active-tab]) 0)
tabs (get-in db [ :config :features :work-list :tabs])
active-tab (nth tabs index)
search-args (search-args-from-filter db active-tab)
updated-args (if (some? last-updated) {:updated-after last-updated})
work-list-eng-tab-search-event [::eng/search-engagements (merge updated-args search-args) false]
eng-search-needed? (and engagements? (some? work-list-eng-tab-search-event))
fx (util/fx-map
(if eng-search-needed? [:dispatch work-list-eng-tab-search-event])
(if log-refresh [::fx/log (str "Refreshed work list tab " active-tab " at " (t/now))]))]
(if (some? (get-in db [ :auth :session :id-token]))
(merge fx {:db (assoc-in db [ :modules :work-list :last-updated] (str (t/now)))})))))Ooh that’s a real good clue
it seems like maybe fn-traced may hate division? removing the parseInt did not remove the NPE
but removing (/ n m) did