clojurescript

Ryan 2025-09-29T13:39:34.358299Z

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)

Ryan 2025-09-29T13:39:48.638179Z

t is juxt’s tick. Any clues?

Ryan 2025-09-29T13:40:14.759119Z

if I replace the (/ (js/parseInt refresh-time) 1000) with a static number, no problem at all

Ryan 2025-09-29T13:40:42.331859Z

if I leave it: 68 | (reg-event-fx 69 | work-list-refresh 70 | (fn-traced [{:keys [db]} [ ]] ---------^---------------------------------------------------------------------- null NullPointerException:

p-himik 2025-09-29T13:45:19.582959Z

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.

Ryan 2025-09-29T13:45:32.825909Z

sure thing

vanelsas 2025-09-29T13:50:02.558729Z

You have to make sure refresh-time isn't nil or "". js/parseInt won't enjoy a nil or blank? value

p-himik 2025-09-29T13:50:32.873589Z

The NPE is during compilation, not run time.

Ryan 2025-09-29T13:51:23.266799Z

yeah the db values referenced are set by the init-db event that runs first or near first

vanelsas 2025-09-29T13:51:36.656059Z

right, sorry, was too quick

👍 1
p-himik 2025-09-29T13:53:28.396889Z

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).

🙏 1
Ryan 2025-09-29T13:53:34.850309Z

(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)))})))))

Ryan 2025-09-29T13:54:07.759999Z

Ooh that’s a real good clue

Ryan 2025-09-29T13:54:34.919089Z

it seems like maybe fn-traced may hate division? removing the parseInt did not remove the NPE

Ryan 2025-09-29T13:54:44.347669Z

but removing (/ n m) did