I'm proposing we add a spec for it, which would conform to success or error.


Something like this, perhaps?



user=> (s/def ::result (s/and (s/keys ::req [(or ::ok ::error)]) #(not (and 
(contains? % ::ok) (contains? % ::error)))))

:user/result

user=> (s/valid? ::result {::ok 1})

true

user=> (s/valid? ::result {::error "bad!"})

true

user=> (s/valid? ::result {::error "bad!" ::ok "wat?"})

false



And, presumably, some helper functions to construct an “ok” or “error” result, 
and maybe ask if a result is “ok?” or “error?”, and maybe some convenient 
accessors? Or just ::ok and ::error directly?



Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood



________________________________
From: clojure@googlegroups.com <clojure@googlegroups.com> on behalf of Didier 
<didi...@gmail.com>
Sent: Friday, October 26, 2018 8:45:23 PM
To: Clojure
Subject: RE: An Error spec?

> I’m genuinely curious as to what you (and other folks) would like to see 
> added to Clojure to satisfy this “need”.

I'm proposing we add a spec for it, which would conform to success or error.

This would still allow flexibility in that you can choose your own error 
structure, and success structure. But it would also add a convention to at 
least formally specify predictable errors.

You can then know if what you got is an error or not by conforming it against 
the spec.

And you can tell if something can return predictable errors, as well as success 
values and exceptions by seeing that the return is of the errorable spec (or 
some other name we can come up with).

Personally I feel this would be good enough, and it seems to respect the 
general Clojure mindset of dynamism and flexibility and not making concrete 
choices for you. And I'd be happy with that.

You could, though that's not something I care for, go further and provide a 
standard error record in core, or a standard error protocol. That said, I feel 
that would maybe be a bit too far, especially, it feels like it might go a 
little against the spirit of Clojure till now. Since I know of no standard 
records, and very little standard protocols.

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to