From cde3779c602406ef6c41d33fce44092bb8c5b315 Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Mon, 6 Nov 2023 16:11:11 +0000 Subject: [PATCH] Clearer error on invalid Plugin (#8023) --- pydantic/plugin/_schema_validator.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pydantic/plugin/_schema_validator.py b/pydantic/plugin/_schema_validator.py index 3610a32d07..7186ece61d 100644 --- a/pydantic/plugin/_schema_validator.py +++ b/pydantic/plugin/_schema_validator.py @@ -70,9 +70,12 @@ def __init__( json_event_handlers: list[BaseValidateHandlerProtocol] = [] strings_event_handlers: list[BaseValidateHandlerProtocol] = [] for plugin in plugins: - p, j, s = plugin.new_schema_validator( - schema, schema_type, schema_type_path, schema_kind, config, plugin_settings - ) + try: + p, j, s = plugin.new_schema_validator( + schema, schema_type, schema_type_path, schema_kind, config, plugin_settings + ) + except TypeError as e: # pragma: no cover + raise TypeError(f'Error using plugin `{plugin.__module__}:{plugin.__class__.__name__}`: {e}') from e if p is not None: python_event_handlers.append(p) if j is not None: