day8 / re-frame-debux

A fork of debux for tracing re-frame code (for eventual consumption by re-frame-10x)
Eclipse Public License 1.0
43 stars 7 forks source link

Assert failed: indent was not correctly replaced for form (not (on-listing-page?)) #23

Closed Vinai closed 4 years ago

Vinai commented 6 years ago

The browser console asked me to report this error:

Assert failed: indent was not correctly replaced for form (not (on-listing-page?))

This is a bug, please report it to https://github.com/Day8/re-frame-debux
(integer? indent)
    at debux$common$util$spy_first (util.cljc?rel=1530343135746:343)
    at re_frame.core.reg_event_fx.call.map__62260 (events.cljs?rel=1530343137437:320)
    at std_interceptors.cljc?rel=1530343117279:148
    at re_frame$std_interceptors$fx_handler__GT_interceptor_$_fx_handler_before (std_interceptors.cljc?rel=1530343117279:145)
    at re_frame$interceptor$invoke_interceptor_fn (interceptor.cljc?rel=1530343116517:68)
    at re_frame$interceptor$invoke_interceptors (interceptor.cljc?rel=1530343116517:106)
    at re_frame$interceptor$execute (interceptor.cljc?rel=1530343116517:199)
    at re_frame$events$handle (events.cljc?rel=1530343116651:65)
    at re_frame.router.EventQueue.re_frame$router$IEventQueue$_process_1st_event_in_queue$arity$1 (router.cljc?rel=1530343116864:178)
    at re_frame$router$_process_1st_event_in_queue (router.cljc?rel=1530343116864:84)
danielcompton commented 6 years ago

Thanks, can you share the entire form that this failed on?

Vinai commented 6 years ago

Okay, it's a little ugly hack. A subscription is called from within an event handler.

(defn- on-listing-page? []
  @(re-frame/subscribe [:current-page/on-listing?]))

(reg-event-fx :videos/search
              (fn-traced [{:keys [db]} [_ term]]
                (cond-> {:db (assoc db :search term)}
                  (not (on-listing-page?)) (assoc :dispatch [:browser/navigate :content]))))

The [:current-page/on-listing?] subscription in turn depends on a couple of other subscriptions, in the end all depending only on the app-db state.

danielcompton commented 6 years ago

Ah, sorry about this. In the meantime, removing the fn-traced will stop the issue from occurring (but of course you then can't trace the event handler).

Vinai commented 6 years ago

Thanks, yes - it was working before I introduced the fn-traced, so I already "fixed" it back again.

Thanks so much for all your awesome work!

conan commented 6 years ago

I have the same issue:

Uncaught Error: Assert failed: indent was not correctly replaced for form applications

This is a bug, please report it to https://github.com/Day8/re-frame-debux
(integer? indent)
    at debux$common$util$spy_first (util.cljc?rel=1528716662972:343)
    at re_frame.core.reg_event_db.call.vec__70642 (events.cljs?rel=1531126466372:31)
    at std_interceptors.cljc?rel=1528716659806:115
    at re_frame$std_interceptors$db_handler__GT_interceptor_$_db_handler_before (std_interceptors.cljc?rel=1528716659806:111)
    at re_frame$interceptor$invoke_interceptor_fn (interceptor.cljc?rel=1528716644162:68)
    at re_frame$interceptor$invoke_interceptors (interceptor.cljc?rel=1528716644162:106)
    at re_frame$interceptor$execute (interceptor.cljc?rel=1528716644162:199)
    at re_frame$events$handle (events.cljc?rel=1528716659235:65)
    at re_frame.router.EventQueue.re_frame$router$IEventQueue$_process_1st_event_in_queue$arity$1 (router.cljc?rel=1528716659400:178)
    at re_frame$router$_process_1st_event_in_queue (router.cljc?rel=1528716659400:84)
    at re_frame.router.EventQueue.re_frame$router$IEventQueue$_run_queue$arity$1 (router.cljc?rel=1528716659400:197)
    at re_frame$router$_run_queue (router.cljc?rel=1528716659400:86)
    at router.cljc?rel=1528716659400:145
    at re_frame.router.EventQueue.re_frame$router$IEventQueue$_fsm_trigger$arity$3 (router.cljc?rel=1528716659400:168)
    at re_frame$router$_fsm_trigger (router.cljc?rel=1528716659400:80)
    at router.cljc?rel=1528716659400:186

It appears to be failing in an event handler, which looks like this:

(rf/reg-event-db :init/success
  [db/validate-interceptor]
  (fn-traced [db [_ {{:keys [:ef/applications :ef/job-posts :web.session/consent?]} :body :as _response}]]
    (log/debug "Loaded" (count job-posts) "job posts")
    (cond-> db
      (seq applications) (assoc :ef/applications (into [] applications))
      (seq job-posts) (assoc :ef/job-posts job-posts)
      consent? (assoc :web.session/consent? consent?))))

I see the "Loaded X job posts" in the console, so I'm guessing it's to do with the db that gets returned. The db/validate-interceptor looks like this:

(defn validate
  "Returns nil if the db conforms to the spec, throws an exception otherwise"
  [spec db]
  (when-let [error (s/explain-data spec db)]
    (throw (ex-info (str "DB spec validation failed: " (expound/expound-str spec db)) error))))

(def validate-interceptor (rf/after (partial validate :ef/db)))

The issue appeared when I changed my :init/success handler from a reg-event-fx to a reg-event-db; I don't see the issue when using reg-event-fx, so that may be a more useful workaround as it allows event tracing.

conan commented 5 years ago

update: i've seen this with reg-event-fx as well. not using traced functions is the only solution i know.

andrewsuzuki commented 4 years ago

Seems to be related to #29. It occurs when I use the cond-> macro.

prook commented 4 years ago

Confirming that this error disappears after removing/replacing cond-> in fn-trace.

stumitchell commented 4 years ago

cond-> is now fixed in master will release soon