This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-02-03
Channels
- # announcements (8)
- # aws (2)
- # babashka (16)
- # beginners (173)
- # calva (13)
- # cider (4)
- # cljfx (6)
- # cljs-dev (108)
- # clojure (63)
- # clojure-australia (2)
- # clojure-dev (10)
- # clojure-europe (73)
- # clojure-italy (8)
- # clojure-nl (4)
- # clojure-norway (5)
- # clojure-uk (4)
- # clojurescript (49)
- # clojureverse-ops (4)
- # community-development (3)
- # core-async (23)
- # cursive (3)
- # data-science (5)
- # datomic (25)
- # emacs (3)
- # events (1)
- # fulcro (13)
- # helix (5)
- # introduce-yourself (1)
- # lein-figwheel (1)
- # lsp (36)
- # malli (1)
- # meander (2)
- # membrane (4)
- # music (8)
- # nextjournal (51)
- # off-topic (47)
- # other-languages (5)
- # pathom (31)
- # pedestal (5)
- # planck (14)
- # polylith (5)
- # portal (1)
- # re-frame (30)
- # react (2)
- # reagent (24)
- # releases (1)
- # rewrite-clj (18)
- # ring (9)
- # sci (33)
- # shadow-cljs (49)
- # testing (3)
- # tools-build (21)
- # tools-deps (29)
- # vim (19)
- # web-security (1)
- # xtdb (12)
A question on parse-uuid
…
I note that parse-long
, parse-double
and parse-boolean
will all throw an IllegalArgumentException
if they are provided anything other than a string. However, parse-uuid
doesn’t test for this, and so it will throw a ClassCastException
if provided with something that isn’t a string. It’s an exception either way, but it seems inconsistent. Is there a reason for this inconsistency, please?
The parsing functions that test will all call the internal function parsing-err
to describe the problem, but parse-uuid
just lets it fall through
the philosophy here is that the parse- functions are defined for strings. for non-string, behavior is undefined.
they happen to throw exceptions in these cases but the type is not prescribed
so you are free to do anything in cljs in these cases - I'd recommend throwing but don't care what specifically is thrown
I was looking to duplicate the behavior, and for each of them I’m testing with
(if (string? s)
...parse...
(throw (js/Error. (parsing-err s))))
But when I got to parse-uuid
I noticed that it’s not like this, so I thought I’d check if that’s how you actually intended it to bewhat the docstring says is what we commit to and these docstrings don't mention what happens if you give it something other than a string (I'd spec them as taking string?
)
On clj, it’s up to the core team, but it really is an illegal argument. It should never be passed. And other functions (that predate ex-info
) were already doing this. So it makes sense that they would continue to take this approach. The core abhors changing behavior, and for new functions to be consistent with existing ones matters.
On cljs, I’m following precedent, meaning that I’ll throw an exception just like clj does, and also I’m throwing the same kind of exception that other parts of cljs.core throws when clojure.core throws IllegalArgumentExceptions