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

Make Contract messages more user-friendly #23

Open
averagehat opened this issue Jan 13, 2016 · 2 comments
Open

Make Contract messages more user-friendly #23

averagehat opened this issue Jan 13, 2016 · 2 comments

Comments

@averagehat
Copy link
Contributor

e.g.

contracts.interface.ContractNotRespected: Breach for argument 'outdir' to run_sample_sheet().
Shouldn't have satisfied the clause exists.
checking: !exists for value: Instance of <type 'str'>: './'
checking: str,!exists for value: Instance of <type 'str'>: './'
Variables bound in inner context:

Could become

contracts.interface.ContractNotRespected: Breach for argument 'outdir' to run_sample_sheet().
=====================
ERROR:  blah blah blah
======================
checking: !exists for value: Instance of <type 'str'>: './'
checking: str,!exists for value: Instance of <type 'str'>: './'
Variables bound in inner context:

Do this by raising a ValueError rather than returning false. Example:

def fails(x):
    raise ValueError("="*9 + "\nERROR: blah blah blah, do xyz\n" + "="*9)
contracts.new_contract("failit", fails)
contracts.decorate(lambda x: x, x="failit")(1)

I would just wrap our current boolean-returning functions

def wrap_validation(func, message):
   def ret_func(arg):
      if not func(arg): 
         raise ValueError(message)
   return ret_func

contracts.new_contract("is_truthy", wrap_validation(lambda x: bool(x), "Not truthy, use truthy input"))
@necrolyte2
Copy link
Member

It needs to be very explicit in what is wrong, that is, it should say exactly what the issue is

Like for the !exists issue, it sould say something like

Error: Directory X already exists

@averagehat
Copy link
Contributor Author

This is better as a PR against the contracts library.

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