Fork me on GitHub
#clojure-uk
<
2018-08-23
>
alexlynham07:08:13

mmmmmmmmmmmorning

dominicm08:08:09

Good morrow

rickmoynihan08:08:56

Can anyone here explain this?

zib.handler.resource>  (java.net.URI. "")
#object[java.net.URI 0x17404268 ""]
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en-GB"><head><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"><meta href="https://play.google.com/?hl=en&tab=w8">Play</a> ;google.jsc && google.jsc.m(m);})();..... </script></div></body></html>

rickmoynihan08:08:43

It looks like cider is fetching the URI object and printing its contents

😮 4
maleghast08:08:06

Hello All 🙂

maleghast08:08:30

Anyone up for telling me how I am being an idiot wrt to these routes?

(defn admin-routes
  "Routes for the 'foundation' admin section"
  [db]
  ["/admin"
   [
    ["" (index)]
    ["/organisation"
     [
      ["" (organisation-index db)]
      ["/add" (organisation-add db)]
      ["/logo" (organisation-logo db)]
      ["/:organisation-id" (organisation-detail db)]]]
    ["/user"
     [
      ["" (user-index db)]
      ["/:user-id" (user-detail db)]]]
    ["/setup"
     [
      ["" (setup-index)]
      ["/setup-db" (setup-db db)]
      ["/setup-reset-baphomet" (reset-db db)]]]]])

dominicm09:08:16

What are you using a colon in your route definition for?

maleghast09:08:04

Ah, you replied in a thread - I never notice that, when people do that... Thanks for answering, I was not ignoring you 🙂

maleghast08:08:00

I keep getting a 404 for /admin/organisation/:organisation-id

maleghast08:08:09

(all the other routes work as expected)

maleghast08:08:17

@thomas - Well the routes are Bidi routes, but I am using them to target Yada resources.

thomas08:08:36

aah ok, maybe ask over in #juxt

thomas08:08:48

but nothing jumps out.. I agree

maleghast08:08:54

That's a good idea - didn't know that they had a channel!

agile_geek08:08:48

Bore da pawb welsh_flag

maleghast08:08:11

Bore da

👏 4
guy08:08:55

Morning!

rickmoynihan09:08:05

Turns out cider does this ⬆️

guy09:08:06

:thinking_face:

rickmoynihan09:08:06

feels wrong to me, the URI is a reference. I could understand that if I did the equivalent of @(URI. "")

guy09:08:20

is it a bit like when you slurp a url?

rickmoynihan09:08:28

yeah its exactly that

guy09:08:26

I guess u are asking the repl to eval the uri?

guy09:08:35

so from my naive perspective that makes sense

guy09:08:22

> You can disable this behavior if you don’t like it.

guy09:08:30

(setq cider-repl-use-content-types nil)

guy09:08:35

problem solved

maleghast09:08:40

Is it wrong that I think it's cool that CIDER does that..?

guy09:08:48

i think its pretty neat yeah

firthh09:08:20

I think it's pretty cool. I am slightly surprised it does it by default though

guy09:08:31

it sounds like its a new feature

maleghast09:08:17

Also, I like that the map is of the region where I live 😉

maleghast09:08:22

Although, I can't get it to work in my CIDER buffer...

rickmoynihan09:08:58

M-x cider-repl-toggle-content-types

rickmoynihan09:08:44

Don’t get me wrong I think the features kinda cute; but usually it just results in your REPL filing with garbage (i.e. HTML output); and I think the operation is done on the wrong thing; the URI is not the image, it’s the pointer to the image. This should only really happen on java.awt.BufferedImages and the like… i.e. if you deref the URI; (though I don’t think Deref is actually a protocol in clojure — but is in cljs)

maleghast09:08:39

Do I need to be using GUI Emacs as well..? In my Emacs buffer I just get #[object java.net.URI ...] etc.

maleghast09:08:06

I see where you are coming from, for sure.

rickmoynihan09:08:04

Yeah… would probably also need to be compiled with image support etc…

mccraigmccraig09:08:32

@maleghast do /admin/organisation and /admin/organisation/add match ok ?

maleghast09:08:07

and /admin/organisation/logo as well

maleghast09:08:11

the id is a string representation of a UUID, e.g. -> 0ac7f61d-657d-5e37-9589-94f41079508b

guy09:08:52

@maleghast i think u have ur keywords as string

guy09:08:55

is that right?

guy09:08:12

"/:organisation-id"

guy09:08:17

or maybe im being thick :thinking_face:

guy09:08:37

i thought they usually do ["articles/" :id "/article.html"]

maleghast09:08:12

@guy - That's worth a try, thanks!

guy09:08:24

im just googling for some examples

maleghast09:08:48

You is a genius, @guy!

guy09:08:49

maybe like that i dnno

maleghast09:08:55

That is exactly it! 🙂

👍 8
guy09:08:18

ah look @dominicm got there first

guy09:08:21

i think u just missed his comment haha

guy09:08:24

i just saw now

maleghast09:08:23

Yeah, I have re-defined it now: [["/" :organisation-id] (organisation-detail db)]]]

guy09:08:30

:thumbsup:

guy09:08:36

and ur user-id one

guy09:08:45

i think :thinking_face:

maleghast09:08:42

Yeah, I need to do that one as well, but I've not implemented the Yada resource or the template for that one yet. Still I will update the route now.

guy10:08:11

:thumbsup:

mccraigmccraig11:08:57

TIL: Throwable->map considered harmful

mccraigmccraig11:08:32

we were using it to make some exceptions serializable... but we ended up with undeserializable tags in the data anyway

mccraigmccraig11:08:17

since it's just for error investigation purposes we'll switch to printing the exceptions to a string and serializing that instead

dominicm11:08:47

clojure core is not very careful about making things serializable. prepl has been criticized for this. Compared with other edn repls like unrepl, which do the right thing(tm)

bronsa11:08:27

serializable as in pr-str<->read-string?

mccraigmccraig11:08:49

@bronsa the output of pr-str will get put in a structure which gets EDN serialized... we don't need to do anything apart from visually inspect the exceptions

bronsa11:08:49

I don't get what you mean when you say that the output of Throwable->map is not serializable -- does it generate unreadable symbols?

mccraigmccraig11:08:59

@bronsa i don't think it's Throwable->map's fault - it's probably an ex-info with some unserializable stuff in its map

bronsa11:08:07

ah, fair enough

mccraigmccraig11:08:20

there were #object tags in the output

mccraigmccraig11:08:40

i guess i didn't think through the implication of using Throwable->map carefully

bronsa11:08:46

yeah that's definitely the ex-data then

bronsa11:08:42

FWIW

user=> (binding [*default-data-reader-fn* tagged-literal] (read-string (pr-str (Throwable->map (ex-info "" {:k (reify Object)})))))
#error {:cause "", :data {:k #object [user$eval171$reify__172 896138248 "user$eval171$reify__172@3569fc08"]}, :via [{:type clojure.lang.ExceptionInfo, :message "", :data {:k #object [user$eval171$reify__172 896138248 "user$eval171$reify__172@3569fc08"]}, :at [clojure.core$ex_info invokeStatic "core.clj" 4754]}], :trace [[clojure.core$ex_info invokeStatic "core.clj" 4754] [clojure.core$ex_info invoke "core.clj" 4754] [user$eval171 invokeStatic "NO_SOURCE_FILE" 15] [user$eval171 invoke "NO_SOURCE_FILE" 15] [clojure.lang.Compiler eval "Compiler.java" 7069] [clojure.lang.Compiler eval "Compiler.java" 7032] [clojure.core$eval invokeStatic "core.clj" 3206] [clojure.core$eval invoke "core.clj" 3202] [clojure.main$repl$read_eval_print__8720$fn__8723 invoke "main.clj" 243] [clojure.main$repl$read_eval_print__8720 invoke "main.clj" 243] [clojure.main$repl$fn__8729 invoke "main.clj" 261] [clojure.main$repl invokeStatic "main.clj" 261] [clojure.main$repl_opt invokeStatic "main.clj" 325] [clojure.main$main invokeStatic "main.clj" 424] [clojure.main$main doInvoke "main.clj" 387] [clojure.lang.RestFn invoke "RestFn.java" 397] [clojure.lang.AFn applyToHelper "AFn.java" 152] [clojure.lang.RestFn applyTo "RestFn.java" 132] [clojure.lang.Var applyTo "Var.java" 702] [clojure.main main "main.java" 37]]}

👍 4
mccraigmccraig11:08:20

ah, neat @bronsa - i wasn't aware of tagged-literal

jasonbell12:08:01

morning

👋 16
dominicm14:08:01

oh, that's a neat trick

bronsa15:08:56

*default-data-reader-fn* should be bound to tagged-literal by default, really, no idea why they didn't do it

rickmoynihan18:08:46

Compatibility, IIRC tagged-literal was introduced in 1.7, *default-data-reader-fn* 1.5.

bronsa18:08:35

right yeah, my gripe is that - they didn't add tagged-literal at the same time that tagged literals were introduced (which tools.reader did) - they didn't bind *defafult-data-reader-fn* when they did introduce tagged-literal

👍 4
bronsa18:08:03

compatibility is not a valid reason, setting a root binding to a previously unbound var is not going to break any existing code

rickmoynihan18:08:43

it is breaking though isn’t it? The difference between an exception being raised and it letting things through.

bronsa18:08:07

uh? no I wouldn't say that

bronsa18:08:13

supporting new behaviour is not a breaking change

bronsa18:08:51

that's the "accretion" definition of rhickey

rickmoynihan19:08:03

Yeah I did ummm and errr a little about this too, but in this case it is changing existing documented behaviour though. That var previously stored a root value of nil and read when it’s nil is promised to throw an exception. I’d argue because it’s been documented this isn’t accretion, it’s taking something away and replacing it with something else.

danielneal16:08:31

Oh man i need to do this

danielneal16:08:54

Those pesky # object