How to use the cfgv.ValidationError function in cfgv

To help you get started, we’ve selected a few cfgv examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github asottile / cfgv / cfgv.py View on Github external
def check_array_fn(v):
        if not isinstance(v, (list, tuple)):
            raise ValidationError(
                f'Expected array but got {type(v).__name__!r}',
            )

        for i, val in enumerate(v):
            with validate_context(f'At index {i}'):
                inner_check(val)
    return check_array_fn
github asottile / cfgv / cfgv.py View on Github external
def check_one_of_fn(v):
        if v not in possible:
            possible_s = ', '.join(str(x) for x in sorted(possible))
            raise ValidationError(
                f'Expected one of {possible_s} but got: {v!r}',
            )
github pre-commit / pre-commit / pre_commit / clientlib.py View on Github external
def check_type_tag(tag):
    if tag not in ALL_TAGS:
        raise cfgv.ValidationError(
            'Type tag {!r} is not recognized.  '
            'Try upgrading identify and pre-commit?'.format(tag),
        )
github asottile / cfgv / cfgv.py View on Github external
def check_regex(v):
    try:
        re.compile(v)
    except re.error:
        raise ValidationError(f'{v!r} is not a valid python regex')
github asottile / cfgv / cfgv.py View on Github external
def load_from_filename(
        filename,
        schema,
        load_strategy,
        exc_tp=ValidationError,
):
    with reraise_as(exc_tp):
        if not os.path.exists(filename):
            raise ValidationError(f'{filename} does not exist')

        with open(filename, encoding='utf-8') as f:
            contents = f.read()

        with validate_context(f'File {filename}'):
            try:
                data = load_strategy(contents)
            except Exception as e:
                raise ValidationError(str(e))

            validate(data, schema)
            return apply_defaults(data, schema)
github asottile / cfgv / cfgv.py View on Github external
def _require_key(self, dct):
    if self.key not in dct:
        raise ValidationError(f'Missing required key: {self.key}')
github pre-commit / pre-commit / pre_commit / clientlib.py View on Github external
def check(self, dct):
        if dct.get('repo') in {LOCAL, META}:
            self._cond('rev').check(dct)
            self._cond('sha').check(dct)
        elif 'sha' in dct and 'rev' in dct:
            raise cfgv.ValidationError('Cannot specify both sha and rev')
        elif 'sha' in dct:
            self._cond('sha').check(dct)
        else:
            self._cond('rev').check(dct)