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

change pprint-str to print-str #15

Merged
merged 2 commits into from
Jan 25, 2021

Conversation

kbaba1001
Copy link
Contributor

Because the error messages is only string, I think print-str looks better than pprint-str.
For example, when an error message has \n :

user=> (clojure.pprint/pprint "aaa\nbbb")
"aaa\nbbb"
nil
user=> (print "aaa\nbbb")
aaa
bbbnil

"aaa\nbbb" has raw \n instead of newline, but I'd like to show newline on messages.

@totakke
Copy link
Member

totakke commented Jan 23, 2021

Thank you for the PR.

The concept of cruler is a validation framework for non-programmers as well as programmers, so human-readable error texts formatted by pprint-str are mandatory.

When a Clojure data structure supplied to error-value is complicated, an error text generated by print-str is so difficult to read.

dev-resources/sample-validator/approved-drug/test.yml
  error: Should be distincted: :drug
    [{:drug foo, :types [{:category A, :serial 1234}], :comment A1} {:drug bar, :types [{:serial 9876}], :comment A2} {:drug bar, :types [{:serial 9876}], :comment A2}] ...
  line: unknown

pprint-str formats such a data structure.

dev-resources/sample-validator/approved-drug/test.yml
  error: Should be distincted: :drug
    [{:drug "foo", :types [{:category "A", :serial 1234}], :comment "A1"}
     {:drug "bar", :types [{:serial 9876}], :comment "A2"}
     {:drug "bar", :types [{:serial 9876}], :comment "A2"}]
     ...
  line: unknown

If you want to use the former error text generated by print-str, I suggest adding a formatting config like :format {:error-value :print} (default :pprint) to cruler.edn and switching an output process regarding to the config.

@kbaba1001 kbaba1001 force-pushed the change-error-messages-print-format branch from ef0f992 to 768bebd Compare January 25, 2021 03:48
@kbaba1001 kbaba1001 force-pushed the change-error-messages-print-format branch from 768bebd to 34b2926 Compare January 25, 2021 05:13
@kbaba1001
Copy link
Contributor Author

@totakke Thank you for the review. I defined :format {:error-value :print} in cruler.edn. Could you check it out, please?

Copy link
Member

@totakke totakke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you.

@totakke totakke merged commit 899c1ef into xcoo:main Jan 25, 2021
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

Successfully merging this pull request may close these issues.

None yet

2 participants