Welcome! Please see the About page for a little more info on how this works.

+5 votes
in Syntax and reader by
closed by

When we write a symbol in the UUID literal, the reported error message is wrong

(as of 1.11.1)

clojure -M -e '#uuid id'
Execution error (AssertionError) at clojure.main/main (main.java:40).
Assert failed: (string? form)

It is wrong because

It should be something like this

Reader error (AssertionError) at clojure.uuid/default-uuid-reader (uuid.clj:12).
Assert failed: (string? form)

A second step improvement could be add spec support to data-literals, as macros do.

Syntax error reading #uuid id at (REPL:1)
id - failed: string? at: [:form]

From #clojure-dev slack channel

Alex: You don’t need anything special there - just an instrumented spec on the data reader fn

After run

(s/fdef clojure.uuid/default-uuid-reader :args (s/cat :form string?))
(clojure.spec.test.alpha/instrument `clojure.uuid/default-uuid-reader)

The message turns into

Syntax error reading source at (REPL:2:1).
Call to #'clojure.uuid/default-uuid-reader did not conform to spec.

This is a way better message.

Also, it includes a #:clojure.error{:phase :read-source} in ex-data.
So the fix could be just add a spec to clojure.uuid/default-uuid-reader

closed with the note: Patch applied to explicitly test and throw a runtime exception, improving the reporting. Advice for data reader fns updated on site.

1 Answer

+2 votes
by
by
Thnks Alex. a brief comment: custom data readers that use assert's will still be bad reported. I think that solutions that suppose less about the data-reader (ie. catch throwable) would be nicer.
...