equinor / configsuite

Config Suite is the result of recognizing the complexity of software configuration.
Other
7 stars 13 forks source link

Make @{transformation,validator}_msg more readable #113

Open pinkwah opened 4 years ago

pinkwah commented 4 years ago

Currently, we give badly worded messages when validations fail, such as Is x a string failed for ....

I propose using string.Formatter to generate messages that are easier for humans to parse. For example:

@validator_msg("Expected {name} to be a list, got {type} instead")
def _is_list(x):
  pass

@validator_msg("Expected {name} to be a valid ISO8601(YYYY-mm-dd) date format")
def _is_date(x):
  pass

@validator_msg("Is x an old validator msg")
def _yes(x):
  pass

string.Formatter can check how many fields there are. If 0, then it can format the message as before. Otherwise we can try to subsitute name and type (and maybe others) with relevant data.

markusdregi commented 4 years ago

I completely agree with you! :+1: The change should be populated through our current types, as well as documentation, examples and best practices.