Pretty print error logging
danielcompton opened this issue · 7 comments
The error messages printed by schema are sometimes quite tricky to parse, for example:
The schema that generated it was quite simple:
(def outstanding-query
{:token UUID
:query {s/Keyword s/Any}
:out-ch async-protocols/WritePort
:err-ch async-protocols/WritePort})
but it is very difficult to understand which part doesn't match the schema, and importantly, what the actual value is if it's not matching the schema.
Pretty printing the message in the ex-info would be quite helpful, however I suspect part of the responsibility for pretty printing this might actually fall to the user (e.g. me) to catch and pretty print the data in the ex-info?
As you mention, I think this is beyond the scope of what we'd want to put in schema.core. But I think there are already other libraries/plugins that do precisely what you want (pretty-print the ex-info) -- In particular, maybe look at io.aviso/pretty ?
I think you're right, the responsibility probably lies elsewhere. Thanks!
Although, in saying that, should the message still be pretty printed? There's no easy way for anyone downstream to pretty print that. This is in ClojureScript btw.
Point taken, thanks. A PR to pretty-print the message body would be welcome.
It appears that the two patches mentioned in the previous comment add TTY codes to the message output. I suppose the intent here is that in a Clojure environment this would eventually go to a TTY-based repl? My question is: what is the intended use in ClojureScript when the ExceptionInfo typically gets thrown and printed to the console. A typical message will look something like the following, with all of the TTY codes just converted to plaintext: "Input to notebook-contents-received does not match schema: ↵↵ �[0;33m [nil nil (not (map? a-object))] �[0m ↵↵"
Is there a better way to view error messages in ClojureScript?
I haven't actually used Schema in cljs for some time, but hopefully someone else will have an answer. If not I'd be open to making this configurable, would just need to think about the best way to do so ...