Skip to content

Pretty-print contracts in error messages 💅 #289

New issue

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

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

Already on GitHub? # to your account

Merged
merged 1 commit into from
Dec 28, 2018

Conversation

frewsxcv
Copy link
Contributor

@frewsxcv frewsxcv commented Oct 28, 2018

Why?

I work on projects that uses contracts.ruby extensively and we have some gnarly contracts. When contract violations happen, we get errors that span many lines, without any indentation or formatting. Having some pretty-printing would greatly help readability when debugging contract violations.

Example!

In addition to the example below, see the new .feature test added in the pull request.

Before

Contract violation for return value: (ReturnContractError)
      Expected: {:a=>(String or Symbol), :b=>(String or Symbol), :c=>(String or Symbol), :d=>(String or Symbol), :e=>(String or Symbol), :f=>(String or Symbol), :g=>(String or Symbol)},
      Actual: {:a=>["foo", "foo"], :b=>["foo", "foo"], :c=>["foo", "foo"], :d=>["foo", "foo"], :e=>["foo", "foo"], :f=>["foo", "foo"], :g=>["foo", "foo"]}
      Value guarded in: Example::run
      With Contract: None => Hash
      At: example.rb:17

After

Contract violation for return value: (ReturnContractError)
      Expected: {:a=>(String or Symbol),
                 :b=>(String or Symbol),
                 :c=>(String or Symbol),
                 :d=>(String or Symbol),
                 :e=>(String or Symbol),
                 :f=>(String or Symbol),
                 :g=>(String or Symbol)},
      Actual: {:a=>["foo", "foo"],
               :b=>["foo", "foo"],
               :c=>["foo", "foo"],
               :d=>["foo", "foo"],
               :e=>["foo", "foo"],
               :f=>["foo", "foo"],
               :g=>["foo", "foo"]}
      Value guarded in: Example::run
      With Contract: None => Hash
      At: example.rb:17

@frewsxcv frewsxcv force-pushed the frewsxcv-pretty-formatting branch 3 times, most recently from 0a88f78 to 99ad6c1 Compare October 29, 2018 00:36

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@frewsxcv frewsxcv force-pushed the frewsxcv-pretty-formatting branch from 99ad6c1 to 0a85410 Compare October 29, 2018 00:38
@frewsxcv
Copy link
Contributor Author

@egonSchiele I know you're busy, and I know the burnout of maintaining open source stuff, so no hard feelings if you don't get to this 🙏 Just wanted to say that if you need help maintaining this, I'm a little familiar with the internals of this library and would be happy to help!

@egonSchiele egonSchiele merged commit 141dfb7 into egonSchiele:master Dec 28, 2018
@egonSchiele
Copy link
Owner

Hey there, sorry for my late response. Thanks for the PR! Yes, I haven't had much time for open source this year so would appreciate any help :) If you see an issue that you want to help with, please submit a PR! Or if you see a PR you think should get merged, just ping me on it.

@frewsxcv frewsxcv deleted the frewsxcv-pretty-formatting branch December 28, 2018 16:55
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants