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

[enhancement] Better display of errors. #261

Open
damaon opened this issue Jun 19, 2017 · 3 comments
Open

[enhancement] Better display of errors. #261

damaon opened this issue Jun 19, 2017 · 3 comments

Comments

@damaon
Copy link

damaon commented Jun 19, 2017

First thanks for developing great library, but I would like to propose enhancement.

When testing this gem for complex params hashes I found that ParamContractError is almost unreadable. I mean structure of error is neat, but what is displayed in Expected: is hardly readable IMO. Also Actual: would be nice with some coloring or adding Errors: as I propose below.

  1. Expected: shows inspected ruby structures instead of how I wrote assertion. Totaly unreadable - I just need to check where type was defined and read it in editor to compare.

  2. I propose also adding output coloring for Actual: - so coloring Red, or at least writing "INCORRECT" where you make mistake in recursive type.

Example:

Expected: StrictHash[{ user: StrictHash[{ name: String , id: Num }]  }]
Actual: { user: { name: { foo: "bar" }, id: 123 }
Errors: { user: { name: "INCORRECT", id:  123 }

I would appreciate feedback about my proposal and tips how this could be implemented.

@damaon
Copy link
Author

damaon commented Jun 19, 2017

I think there should be 3 colors:
Red - incorrect things
Yellow - missing things
Green - OK

But this can be easily expressed with text interface:

Expected: StrictHash[{ user: StrictHash[{ name: String , id: Num }]  }]
Actual: { user: { name: INCORRECT<{ foo: "bar" }>, id: 123, REDUNDANT<last_name: "foo"> }

@egonSchiele
Copy link
Owner

Hi Machiaweliczny!
I like this idea. The change would have to be made here:
https://github.com/egonSchiele/contracts.ruby/blob/master/lib/contracts.rb#L129

Also keep in mind, sometimes it is not appropriate to color. For example, if the output is being written to a file, then the coloring would just add nonsense characters to the output. So you should check if the output is tty before coloring.

@cabe56
Copy link

cabe56 commented Mar 30, 2019

@egonSchiele is this still relevant? Was looking over issues in the repo to see if there was another ticket about errors.

Dunno about coloring in OP, would just love for the error message to tell me 'this key in the hash did not match the contract'.

Have never contributed but would love to take a stab at this one as it would save me a lot of time debugging.

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

3 participants