taoensso / sente

Realtime web comms library for Clojure/Script
https://www.taoensso.com/sente
Eclipse Public License 1.0
1.73k stars 193 forks source link

:advanced compilation failing #86

Closed gbuisson closed 9 years ago

gbuisson commented 9 years ago

Hi! using clojure :advanced, at runtime, i get the following trace on js console:

Uncaught TypeError: Expecting a function in instanceof check, but got [object Object] timers.cljs:20(anonymous function) timers.cljs:20Vp timers.cljs:21b sente.cljs:1073d sente.cljs:1085Qp ioc_helpers.cljs:65(anonymous function) async.cljs:660(anonymous function) async.cljs:180(anonymous function) async.cljs:722(anonymous function) channels.cljs:85zp channels.cljs:28b.port1.onmessage dispatch.cljs:20

is sente known to be working with closure :advanced compilation ? Thank you.

gbuisson commented 9 years ago

almost forgot, i see that on my console while compiling:

ARNING: Use of undeclared Var taoensso.encore/kw-identical? at line 1078 resources/public/prod/taoensso/sente.cljs

ptaoussanis commented 9 years ago

Hi there,

Sounds like you have a dependency conflict. Try add [com.taoensso/encore "1.15.1"] to your project.clj dependencies, above any other com.taoensso deps. That should do the trick.

Cheers! :-)

gbuisson commented 9 years ago

thank you! there is some progress, i added the encore dependency before anything else, got the same error at runtime except i don't have the warning at compile time:

Uncaught TypeError: Expecting a function in instanceof check, but got [object Object] timers.cljs:17(anonymous function) timers.cljs:17 Po timers.cljs:17b encore.cljs:147d sente.cljs:1073Ko ioc_helpers.cljs:65(anonymous function) async.cljs:682(anonymous function) async.cljs:180(anonymous function) async.cljs:739(anonymous function) channels.cljs:85to channels.cljs:28b.port1.onmessage dispatch.cljs:20

ptaoussanis commented 9 years ago

Sente doesn't have a timers.cljs ns, I'm guessing that might be from core.async. You might try clearing your target dir. If that's no good, I'd try the reference Sente example to rule out the possibility that some other dependency you're pulling in is causing an issue.

Cheers :-)

gbuisson commented 9 years ago

ok i'm going to try that.

Thank you!

gbuisson commented 9 years ago

tried the whole day, this bug is a nightmare! removed nearly all dependencies, same error. i think it has to do with something messing with core.async but i'm not sure, i have no clue whatsover.

as soon as the connection to the websocket server is aquired, the bug pops.

ptaoussanis commented 9 years ago

Sorry, to confirm - you get this error message when running the reference example project?

gbuisson commented 9 years ago

no I don't, something has to be wrong my side, but i'm thinking about something outside my code, something related to the environment, maybe in the fields of communications between client/server.

looking at the stack trace, the bug is triggered in core.async from sente right in the router

(defn start-chsk-router!
  "Creates a go-loop to call `(event-msg-handler <event-msg>)` and returns a
  `(fn stop! [])`. Catches & logs errors. Advanced users may choose to instead
  write their own loop against `ch-recv`."
  [ch-recv event-msg-handler & [{:as opts :keys [trace-evs?]}]]
  (let [ch-ctrl (chan)]
    (go-loop []
      (when-not
        (encore/kw-identical? ::stop
          (try
            (let [[v p] (async/alts! [ch-recv ch-ctrl])]
              (if (encore/kw-identical? p ch-ctrl) ::stop
                  (let [{:as event-msg :keys [event]} v]
                  (try
                    (when trace-evs?
                      (tracef "Pre-handler event: %s" event))
                    (if-not (event-msg? event-msg)
                      ;; Shouldn't be possible here, but we're being cautious:
                      (errorf "Bad event: %s" event) ; Log 'n drop
                      (event-msg-handler event-msg))
                    nil
                    (catch                        :default t
                      (errorf        
                        "Chsk router handling error: %s" event))))))
            (catch                        :default t
              (errorf        
                "Chsk router channel error!"))))
        (recur)))
    (fn stop! [] (async/close! ch-ctrl))))
ptaoussanis commented 9 years ago

no I don't

Okay, that's handy to know since it rules out a lot of things.

Any chance I could see your project.clj and routing handler?

gbuisson commented 9 years ago

sure! I just sent you an email, thank you very much!

gbuisson commented 9 years ago

OK, the problem was on my side, in my handler methods, i was using println which is unavailable on prod environment.

The js error displayed was really unhelpful and mislead me.

Thank you for your support, you can close the issue.

ptaoussanis commented 9 years ago

Fantastic, happy to hear you found a solution - thanks for letting me know!

The js error displayed was really unhelpful and mislead me.

Yeah, the Cljs error messages are unfortunately still a little uneven. Some are really good (significantly better than Clojure itself); others can be a little cryptic. It's clear that effort's going into improving them over time, thankfully.

Feel free to ping if you run into any further issues. Cheers! :-)