| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# Copyright (c) 2021 Ansible Project |
| 3 |
# Simplified BSD License (see licenses/simplified_bsd.txt or https://opensource.org/licenses/BSD-2-Clause) |
| 4 |
|
| 5 |
from __future__ import annotations |
| 6 |
|
| 7 |
|
| 8 |
class AnsibleFallbackNotFound(Exception): |
| 9 |
"""Fallback validator was not found""" |
| 10 |
|
| 11 |
|
| 12 |
class AnsibleValidationError(Exception): |
| 13 |
"""Single argument spec validation error""" |
| 14 |
|
| 15 |
def __init__(self, message): |
| 16 |
super(AnsibleValidationError, self).__init__(message) |
| 17 |
self.error_message = message |
| 18 |
"""The error message passed in when the exception was raised.""" |
| 19 |
|
| 20 |
@property |
| 21 |
def msg(self): |
| 22 |
"""The error message passed in when the exception was raised.""" |
| 23 |
return self.args[0] |
| 24 |
|
| 25 |
|
| 26 |
class AnsibleValidationErrorMultiple(AnsibleValidationError): |
| 27 |
"""Multiple argument spec validation errors""" |
| 28 |
|
| 29 |
def __init__(self, errors=None): |
| 30 |
self.errors = errors[:] if errors else [] |
| 31 |
""":class:`list` of :class:`AnsibleValidationError` objects""" |
| 32 |
|
| 33 |
def __getitem__(self, key): |
| 34 |
return self.errors[key] |
| 35 |
|
| 36 |
def __setitem__(self, key, value): |
| 37 |
self.errors[key] = value |
| 38 |
|
| 39 |
def __delitem__(self, key): |
| 40 |
del self.errors[key] |
| 41 |
|
| 42 |
@property |
| 43 |
def msg(self): |
| 44 |
"""The first message from the first error in ``errors``.""" |
| 45 |
return self.errors[0].args[0] |
| 46 |
|
| 47 |
@property |
| 48 |
def messages(self): |
| 49 |
""":class:`list` of each error message in ``errors``.""" |
| 50 |
return [err.msg for err in self.errors] |
| 51 |
|
| 52 |
def append(self, error): |
| 53 |
"""Append a new error to ``self.errors``. |
| 54 |
|
| 55 |
Only :class:`AnsibleValidationError` should be added. |
| 56 |
""" |
| 57 |
|
| 58 |
self.errors.append(error) |
| 59 |
|
| 60 |
def extend(self, errors): |
| 61 |
"""Append each item in ``errors`` to ``self.errors``. Only :class:`AnsibleValidationError` should be added.""" |
| 62 |
self.errors.extend(errors) |
| 63 |
|
| 64 |
|
| 65 |
class AliasError(AnsibleValidationError): |
| 66 |
"""Error handling aliases""" |
| 67 |
|
| 68 |
|
| 69 |
class ArgumentTypeError(AnsibleValidationError): |
| 70 |
"""Error with parameter type""" |
| 71 |
|
| 72 |
|
| 73 |
class ArgumentValueError(AnsibleValidationError): |
| 74 |
"""Error with parameter value""" |
| 75 |
|
| 76 |
|
| 77 |
class DeprecationError(AnsibleValidationError): |
| 78 |
"""Error processing parameter deprecations""" |
| 79 |
|
| 80 |
|
| 81 |
class ElementError(AnsibleValidationError): |
| 82 |
"""Error when validating elements""" |
| 83 |
|
| 84 |
|
| 85 |
class MutuallyExclusiveError(AnsibleValidationError): |
| 86 |
"""Mutually exclusive parameters were supplied""" |
| 87 |
|
| 88 |
|
| 89 |
class NoLogError(AnsibleValidationError): |
| 90 |
"""Error converting no_log values""" |
| 91 |
|
| 92 |
|
| 93 |
class RequiredByError(AnsibleValidationError): |
| 94 |
"""Error with parameters that are required by other parameters""" |
| 95 |
|
| 96 |
|
| 97 |
class RequiredDefaultError(AnsibleValidationError): |
| 98 |
"""A required parameter was assigned a default value""" |
| 99 |
|
| 100 |
|
| 101 |
class RequiredError(AnsibleValidationError): |
| 102 |
"""Missing a required parameter""" |
| 103 |
|
| 104 |
|
| 105 |
class RequiredIfError(AnsibleValidationError): |
| 106 |
"""Error with conditionally required parameters""" |
| 107 |
|
| 108 |
|
| 109 |
class RequiredOneOfError(AnsibleValidationError): |
| 110 |
"""Error with parameters where at least one is required""" |
| 111 |
|
| 112 |
|
| 113 |
class RequiredTogetherError(AnsibleValidationError): |
| 114 |
"""Error with parameters that are required together""" |
| 115 |
|
| 116 |
|
| 117 |
class SubParameterTypeError(AnsibleValidationError): |
| 118 |
"""Incorrect type for subparameter""" |
| 119 |
|
| 120 |
|
| 121 |
class UnsupportedError(AnsibleValidationError): |
| 122 |
"""Unsupported parameters were supplied""" |