Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion - add name of the function where the spec failed to validation error report #51

Closed
LiesbethW opened this issue May 1, 2019 · 2 comments
Labels
enhancement New feature or request

Comments

@LiesbethW
Copy link

When I spec arguments of a function with a validation that occurs often throughout the codebase, it can be hard to find out what function I called with invalid arguments. I suggest to add the speced/defn that failed to the error report.

For example if now I call this function with a nil office id:

(speced/defn create-support-chat-flex-worker [db-conn
                                              ^:datomic/eid flex-worker-id
                                              ^:datomic/eid office-id]
 ...

Where you now get

-- Spec failed --------------------
Validation failed

  nil

evaluated from

  office-id

should satisfy

  pos-int?

-- Relevant specs -------

:datomic/eid:
  clojure.core/pos-int?

-------------------------
Detected 1 error

Would become something like

Validation failed

  nil

evaluated from

  office-id

in speced function

 link.stores.datomic-chat-store/create-support-chat-flex-worker

should satisfy

  pos-int?

-- Relevant specs -------

:datomic/eid:
  clojure.core/pos-int?

-------------------------
Detected 1 error

Even cooler would be if I also knew where this function got called from, but I can imagine that's a lot more involved.

@LiesbethW LiesbethW added the enhancement New feature or request label May 1, 2019
@vemv
Copy link
Contributor

vemv commented May 1, 2019

Just to be clear, do you not get a stracktrace along with with these error reports?

I admit the error reporting (the Validation failed message which comes from Expound) and the stacktrace are disjointed, i.e. the message and the stacktrace can be printed in different places (different windows of your IDE) and at different times (5 seconds later, or interspersed with unrelated output).

But disjointed or not, the stacktrace should be there, which probably would address most of your pains. 95% of the times I don't get disjointed output. (Things that can cause it: running tests, concurrency)

Can you confirm?

Btw, the Expound error reporting is currently hacked (we with-out-str it and manipulate it). If/when bhb/expound#148 is addressed, it might be reasonable to add more handy fields to it, but meanwhile I'd preferably keep the hacking at a minimum.

--

Even cooler would be if I also knew where this function got called from, but I can imagine that's a lot more involved.

(This specific suggestion seems off since it'd largely duplicate Clojure's throw mechanism which already informs you of the stacktrace)

@thumbnail
Copy link
Member

Addressed here: nedap/utils.spec#13

Make sure you're on utils.spec 1.3.0 or later, and you can set the stackframe property to show a (part of?) the stacktrace when a validation failed 🎉.

I personally embedded this in my ~/.lein/profile.clj

 :u.spec {:managed-dependencies [[com.nedap.staffing-solutions/utils.spec "1.3.0"]]
          :jvm-opts ["-Dnedap.utils.spec.print-stack-frames=5"]}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants