Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Custom formatter for ex-info thrown by cljs.spec #23
Currently it's quite tricky to get good output from cljs.spec. Reason being that the ex-info thrown includes the full spec commentary in ex-message. This includes the serialised val which failed. In my case this can fill the console many times over.
Alex Miller recommended catching these exceptions and using the ex-data to present the spec nicely. (e.g. don't print the ex-message to the console). This would be fine except it's difficult to catch all errors due to the nature of how UI code executes (react render loop, re-frame dispatch queue, callbacks)
How about automatically detecting and pretty formatting ex-info errors thrown by cljs.spec?
To keep the ball rolling, I have just tested ExceptionInfo behaviour.
Currently cljs-devtools has pretty nice behaviour, it presents the error printed with IPrintWithWriter protocol. The implementation is questionable because they are re-implementing clojurescript map printer in there, but that is not essential to our issue at hand.
I think nothing is stopping you overriding IPrintWithWriter on ExceptionInfo and doing something better there (e.g. abbreviating long messages).
But I agree that we could do even better job with IFormat. We could reuse string abbreviation logic already implemented in devtools and present other parts as expandable data.
I went down the rabbit hole and proposed a solution upstream:
Let's wait for its resolution before moving forward.