expound

axl316 2018-09-11T03:28:37.000100Z

first time using expound! Looks extremely useful, although, using the example from the readme as is in my repl produces an error -

(s/def :example.place/city string?)
(s/def :example.place/state string?)
(s/def :example/place (s/keys :req-un [:example.place/city :example.place/state]))
(expound/expound :example/place {:city "Denver", :state :CO})
=> :example.place/city
=> :example.place/state
=> :example/place
ExceptionInfo Unknown data:

  clojure.core/ex-info (core.clj:4725)

axl316 2018-09-11T03:29:18.000100Z

what am i missing?

bbrinck 2018-09-11T04:05:28.000100Z

@aymat316 Hm, I’m not sure. How are you requiring expound?

bbrinck 2018-09-11T04:06:08.000100Z

I tend to use lein repl, so if you’re using another REPL, let me know and I’ll try it. Also, what version of Expound and clojure.spec are you using?

axl316 2018-09-11T14:24:56.000100Z

@bbrinck I use nREPL -

nREPL server started on port 55098 on host 127.0.0.1 - <nrepl://127.0.0.1:55098>
REPL-y 0.3.7, nREPL 0.2.12
Clojure 1.9.0-alpha16
Java HotSpot(TM) 64-Bit Server VM 1.8.0_102-b14
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
    Exit: Control+D or (exit) or (quit)
 Results: Stored in vars *1, *2, *3, an exception in *e

axl316 2018-09-11T14:25:45.000100Z

[org.clojure/clojure "1.9.0-alpha16"] [expound "0.7.1"]

bbrinck 2018-09-11T14:35:00.000100Z

Hm, I’d be surprised if it matters, but can you try Clojure 1.9.0 (without the alpha)? I haven’t done regression testing against alphas

bbrinck 2018-09-11T14:36:03.000100Z

Did you start the REPL with lein repl or boot repl?

bbrinck 2018-09-11T14:40:54.000100Z

Ah, yes, I just tried with alpha16 it looks like 0.7.1 is incompatible with alpha16

axl316 2018-09-11T14:43:51.000100Z

I use lein repl .. gonna try with 1.9.0 .. not sure why I was using alpha

👍 1
bbrinck 2018-09-11T15:00:43.000100Z

Did that help?

axl316 2018-09-11T15:06:54.000100Z

yes, that worked, thanks! Although, sadly, I may not have a choice at the moment and might have to stick with alpha16 since we use that across our stack.. will need an upgrade across the board

bbrinck 2018-09-11T15:26:38.000100Z

Ah, I see. I would expect that the upgrade to 1.9.0 should be relatively painless. I haven’t dug through the changelog, but I would imagine it would be mostly bug fixes with few breaking changes.

bbrinck 2018-09-11T15:28:16.000100Z

I was going to suggest an older version of Expound, but it looks like the first supported version is alpha17. Sorry!

axl316 2018-09-11T15:30:44.000100Z

ah damn ! lol .. well good reason for us to finally upgrade.. I hear we tried once but stuff broke on our service layer 🙁 , so we might have to upgrade slowly and carefully .. Thanks @bbrinck for the help!

bbrinck 2018-09-11T15:30:55.000100Z

Good luck!

axl316 2018-09-11T18:01:37.000100Z

looks like I can upgrade to 1.9.0 .. my follow up question, does expound have the ability to return custom error messages as data (similar to s/explain-data), rather than print them? I’m hoping to use the error messaging on the front end

bbrinck 2018-09-11T18:04:54.000100Z

@aymat316 It can return the formatted string, but no, it doesn’t currently have a simple way to return the data. I’m not sure that the explain-data returned by expound would be meaningfully different than the data returned by s/explain-data

bbrinck 2018-09-11T18:07:23.000100Z

Can you talk a little more about what you’d like to do with the data? And how expound/explain-data might differ from s/explain-data? Currently expound just adds a little bookkeeping data that it uses internally, but I’m not sure it’s more widely useful (but I could be wrong)

bbrinck 2018-09-11T18:09:25.000100Z

Of course, you could just get the string with expound/expound-str and return that to front-end, but I don’t know if that helps

axl316 2018-09-11T18:13:36.000100Z

actually I think a return of just the error string should work for me .. I don’t think I need something as elaborate as s/explain-data .. but I’ll need to parse the string. . just wanted to know if there was a function to return to me only the custom error string I’ve defined for the spec (without the --- Spec failed --- etc.)

bbrinck 2018-09-11T18:14:28.000100Z

Ah, no, not yet. You can control some parts of that string though

axl316 2018-09-11T18:15:00.000100Z

yes, I just saw the printer options.. will most likely use that along with some manual parsing

bbrinck 2018-09-11T18:15:02.000100Z

e.g. you can remove that “Relevant” specs section

bbrinck 2018-09-11T18:15:03.000100Z

https://github.com/bhb/expound#printer-options

bbrinck 2018-09-11T18:15:04.000100Z

cool

bbrinck 2018-09-11T18:15:09.000100Z

untested, but basically do this:

bbrinck 2018-09-11T18:15:39.000100Z

(binding [s/*explain-out* (expound/custom-printer {:print-specs? false})]
  (s/explain-str my-spec my-value))

bbrinck 2018-09-11T18:16:09.000100Z

Hopefully in beta timeframe more things will be configurable, and I’ll consider returning the output as structured data instead of a single string

axl316 2018-09-11T18:16:31.000100Z

sounds good! thanks! cool stuff