MCPcopy
hub / github.com/marshmallow-code/marshmallow / make_error

Method make_error

src/marshmallow/fields.py:288–303  ·  view source on GitHub ↗

Helper method to make a `ValidationError` with an error message from ``self.error_messages``.

(self, key: str, **kwargs)

Source from the content-addressed store, hash-verified

286 return And(*self.validators)
287
288 def make_error(self, key: str, **kwargs) -> ValidationError:
289 """Helper method to make a `ValidationError` with an error message
290 from ``self.error_messages``.
291 """
292 try:
293 msg = self.error_messages[key]
294 except KeyError as error:
295 class_name = self.__class__.__name__
296 message = (
297 f"ValidationError raised by `{class_name}`, but error key `{key}` does "
298 "not exist in the `error_messages` dictionary."
299 )
300 raise AssertionError(message) from error
301 if isinstance(msg, (str, bytes)):
302 msg = msg.format(**kwargs)
303 return ValidationError(msg)
304
305 def _validate_missing(self, value: typing.Any) -> None:
306 """Validate missing values. Raise a :exc:`ValidationError` if

Callers 15

_validate_missingMethod · 0.95
_test_collectionMethod · 0.80
_deserializeMethod · 0.80
_deserializeMethod · 0.80
_deserializeMethod · 0.80
_validatedMethod · 0.80
_validatedMethod · 0.80
_validatedMethod · 0.80
_validatedMethod · 0.80
_validatedMethod · 0.80
_deserializeMethod · 0.80
_deserializeMethod · 0.80

Calls 1

ValidationErrorClass · 0.90

Tested by 2

test_make_errorMethod · 0.64