Fork me on GitHub
#hoplon
<
2016-12-21
>
peterromfeld07:12:33

Hi, im trying to add some exception monitoring, since castra is catching all exceptions and does its own stuff to it i can not just use the JVM setDefaultUncaughtExceptionHandler You think its ok if wrap-castra has an optional exception-handler option which has to take the exception as arg, and return the exception back (after you are done with your side effects)

peterromfeld07:12:11

i have on the frontend on-error with mkremote but at that time im already on the frontend and have to callback to the backend and also the exception is not in its original form anymore

peterromfeld09:12:06

actually it would be cool to also get fn-name and args. maybe an on-error on middleware and have something like

(catch Throwable e
           (when on-error (on-error fn-name args e))
           (response body-keys req {:error (ex->clj e)})

jumblerg11:12:59

basically, i'm printing off the handled exceptions to stderr before they're returned back to the client.

jumblerg11:12:51

this should cause them to appear in logs, etc. but i'm not certain this is the optimal approach.

thedavidmeister11:12:23

any reason why hoplon doesn’t use the history functionality from google closure for route cells?

jumblerg11:12:34

i've not looked at google closure's api, but does it wrap the html 5 pushstate api?

jumblerg11:12:40

a better question might be what would we gain from using it?

thedavidmeister11:12:09

i’m not seeing my route cell updating in response to setting the window hash in phantomjs

thedavidmeister11:12:25

but the bidi router did (based on goog)

jumblerg11:12:54

do you happen to know, offhand, if the route cell works in other webkit implementations?

thedavidmeister11:12:15

works fine in chrome

thedavidmeister11:12:18

just tinkering now

thedavidmeister11:12:05

i got a test that looks like

jumblerg11:12:08

i believe webkit and chrome parted ways, chrome uses the blink fork now i think. but the route cell was implemented pre-blink probably.

thedavidmeister11:12:08

(deftest ??handler?=
 (let [h?= (handler?= :home)]
  (navigate! :home)
  (is @h?=)
  (navigate! :privacy)
  (is (not @h?=))))

thedavidmeister11:12:46

passed with a bidi router but not with a route cell

thedavidmeister11:12:08

i’ll give safari a shot

thedavidmeister11:12:22

yeah, works in safari

thedavidmeister11:12:53

i got a (j/cell= (prn route=))

thedavidmeister11:12:06

i see the printout in chrome and safari

thedavidmeister11:12:14

don’t even see it in tests

thedavidmeister11:12:55

navigate! is just a wrapper around bidi and

thedavidmeister11:12:57

(defn set-hash!
 [s]
 {:pre [(string? s)]}
 (-> js/window
     .-location
     .-hash
     (set! s)))

thedavidmeister11:12:34

actually @jumblerg it looks like there is a Html5 and regular Html version of the History management from google

thedavidmeister11:12:12

looks like it has tons of browser support code to make navigation work

thedavidmeister11:12:42

will use the Html5 pushstate api if available

dm311:12:22

makes sense to adopt that into Hoplon or make a separate route-cell lib?

dm311:12:41

btw @jumblerg printing stack trace by default is not a good option 🙂 Most serious deployments use a logger of some sort. You might also want to increment all kinds of stats so best to expose that via something like an on-error callback

thedavidmeister11:12:28

@dm3 well i think i have to do something to get it working, i’ll let you know how i go 🙂

jumblerg11:12:49

@dm3: wouldn't exceptions written to *err* be consequently handled by any logging framework?

dm311:12:27

you mean like system-level logging framework

jumblerg11:12:30

this is not my area of expertise; i started into a deep dive on this yesterday, but cut myself short since i had to ship some code. this was a stopgap solution.

dm311:12:50

like syslog

dm311:12:59

I mean JVM ones like logback or log4j

jumblerg11:12:21

yeah, that's what i'm using.

dm311:12:35

no, they don't pick up anything you don't give to them directly

dm311:12:53

e.g. via clojure.tools.logging

jumblerg11:12:04

i think there's a with-logs fn or something similar than will capture it, but i agree that @peterromfeld's approach is probably a better solution.

dm311:12:08

you should be able to inject a middleware in the RPC chain

dm311:12:18

that'd be a more general solution

jumblerg11:12:11

i suspect there's already a technique for doing this that i'm just not aware of; i find it hard to believe that this case isn't already covered somehow.

jumblerg11:12:35

a middleware that grabs the castra-handled error off the response and logs it?

jumblerg11:12:51

there's probably something like this out there already.

dm311:12:08

yeah, I haven't done much with castra

dm311:12:56

but it seemed like Castra just serialized all of the caught exceptions as a response and never gave a chance to do anything else with them, no?

jumblerg11:12:01

yeah, the exception gets caught and passed up to the client wrapped in an http 200, where it is inflated back into an error.

jumblerg11:12:12

this is handy in many cases, for example, authorization errors (404s), where you want the client to be able to handle the error by reverting to a login screen.

peterromfeld11:12:37

You can make a Middleware but still someone might want the original exception before castra dfl it

peterromfeld12:12:51

i would love to see a on-error option on castra middleware, which calls fn-name/symbol + args + exception on this function 😄

jumblerg12:12:07

@peterromfeld: it seems that something like this would be useful; will definitely make sure we get in right before merging into master. pull my branch and make a pr off of it if you like.

peterromfeld12:12:55

ok ill look into it tomorrow if i can come up with some elegant solution

jumblerg12:12:42

i want to circle back with micha or alan and make sure i'm not missing anything first; there's likely some less obvious technique for doing this already i'm unaware of.

jumblerg12:12:49

maybe some implicit and undocumented change to the environment that may cause certain classes of errors to propagate up into logs instead of being sent across the wire to the client when in production.

peterromfeld12:12:04

you can have a defaulthandler for uncaught exceptions.. but castra catches it 😉

dm312:12:17

that's not a great solution either - you should be able to access the inputs that caused the exception too

peterromfeld12:12:04

yup i also would like that too, more context better for debugging later

thedavidmeister12:12:09

@dm3 this seems to work

thedavidmeister12:12:13

(defn history-cell
 []
 (let [c (j/cell nil)
       history (History.)]
  (j/with-let [_ (j/cell= c #(.setToken history %))]
   (goog.events/listen history goog.History/EventType.NAVIGATE
    (fn [e]
     (reset! c (.-token e))))
   (.setEnabled history true))))

thedavidmeister12:12:21

it works a bit different to a route cell though

thedavidmeister12:12:33

you reset it to navigate

thedavidmeister13:12:07

and yep, that totally fixed my tests

thedavidmeister13:12:31

@jumblerg @dm3 there must be some magic x-browser something in google history that route cell doesn’t have

thedavidmeister13:12:48

because my phantomjs tests are passing now

jblaisure17:12:58

Has anyone used the w2ui library with joplin?

micha18:12:06

@jumblerg sorry been under the gun here at work today, firefighting

jumblerg18:12:34

i'm sure... no worries and no rush at all.

micha18:12:54

had a partial redis meltdown

jumblerg18:12:10

you finally broke it!

micha18:12:19

no radioactive wazste was leaked

jumblerg18:12:28

congratulations?

micha18:12:32

haha yse whew

micha18:12:21

redis is the best software ever

micha18:12:36

antirez deserves free beers wherever he goes

jumblerg18:12:44

well, you've been trying to break it for a long time.

micha18:12:46

in perpetuity

alandipert18:12:19

we should like, send antirez a christmas bonus

micha18:12:27

seriously

jumblerg18:12:27

i guess you deserve a few yourself in light of your most recent success.

alandipert18:12:31

i bet james is down

micha18:12:07

yes, we're doing it