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

Printing messages without newlines or separators #92

Closed
vemv opened this issue May 10, 2018 · 4 comments
Closed

Printing messages without newlines or separators #92

vemv opened this issue May 10, 2018 · 4 comments

Comments

@vemv
Copy link
Contributor

vemv commented May 10, 2018

Hi!

I'm trying to use expound for generating nice ex-info objects.

Example:

(throw (ex-info "Validation failed" {:explanation (with-out-str (println (apply expound/expound args)))}))

The problem is, the \ns and --------------------s don't make sense in this context, they make things less readable:

image

Is there currently an option to remove them?

Thanks - Victor

@bhb
Copy link
Owner

bhb commented May 13, 2018

@vemv Hi, thanks very much for your question!

There is not currently an option to remove the newlines and separators. The error messages in Expound rely on whitespace (including newlines) in a number of cases. For instance, in the following example, the error message relies on newlines to underline the bad part of the map:

;; -- Spec failed --------------------

;;   {:city ..., :state :CO}
;;                      ^^^

;; should satisfy

;;   string?

I can certainly understand why messages without newlines would be useful in your context, but Expound's error messages are intentionally multi-line and verbose to assist with understanding.

A different set of messages that are single-line and compact would be also useful, but out of scope for this particular project.

Thanks!

@bhb bhb closed this as completed May 13, 2018
@vemv
Copy link
Contributor Author

vemv commented May 13, 2018

Thanks for the explanation @bhb !

I might give a shot to a PR, assuming the changes aren't too intrusive.

@bhb
Copy link
Owner

bhb commented May 13, 2018

@vemv I haven't dug in, but off the top of my head, I think it'd require some pretty in-depth design on a number of parts of error messages, including

  1. How to highlight the bad value when it's part of a larger value
  2. How to handle multiple branches of or specs
  3. How to print out tables of missing keys

Just fair warning - you're welcome to make a PR, but I think the bar for this change is pretty high and I'll probably politely decline the PR unless it works across the range of features that Expound includes 😄 .

@vemv
Copy link
Contributor Author

vemv commented May 13, 2018

Again, thanks for the fair warning!

I gave some thought to your feedback.

Probably plain data could do the job:

{:bad-value "X"
 :bad-value-path [0 0 :foo 0] ;; get-in style
 :missing-keys [:x :y :z]
 :branches [...]
 ...
}

Something like that. With a bit of luck, expound could build this data structure first, and present its traditional informational messages on top of that.

It doesn't sound easy but I had been wanting to allocate a day to FOSS!

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

No branches or pull requests

2 participants