diff --git a/haystack/core/pipeline/base.py b/haystack/core/pipeline/base.py index d8f2a6593..155ba27fe 100644 --- a/haystack/core/pipeline/base.py +++ b/haystack/core/pipeline/base.py @@ -167,8 +167,10 @@ class PipelineBase: f"Successfully imported module {module} but can't find it in the component registry." "This is unexpected and most likely a bug." ) - except (ImportError, PipelineError) as e: - raise PipelineError(f"Component '{component_data['type']}' not imported.") from e + except (ImportError, PipelineError, ValueError) as e: + raise PipelineError( + f"Component '{component_data['type']}' (name: '{name}') not imported." + ) from e # Create a new one component_class = component.registry[component_data["type"]] diff --git a/releasenotes/notes/fix-invalid-component-type-error-83ee00d820b63cc5.yaml b/releasenotes/notes/fix-invalid-component-type-error-83ee00d820b63cc5.yaml new file mode 100644 index 000000000..64119cfa8 --- /dev/null +++ b/releasenotes/notes/fix-invalid-component-type-error-83ee00d820b63cc5.yaml @@ -0,0 +1,5 @@ +--- +enhancements: + - | + When `Pipeline.from_dict` receives an invalid type (e.g. empty string), an informative `PipelineError` is now + raised. diff --git a/test/core/pipeline/test_pipeline.py b/test/core/pipeline/test_pipeline.py index 1cd57a5b5..1f0284301 100644 --- a/test/core/pipeline/test_pipeline.py +++ b/test/core/pipeline/test_pipeline.py @@ -564,7 +564,7 @@ class TestPipeline: err.match("Missing 'type' in component 'add_two'") # UNIT - def test_from_dict_without_registered_component_type(self, request): + def test_from_dict_without_registered_component_type(self): data = { "metadata": {"test": "test"}, "components": {"add_two": {"type": "foo.bar.baz", "init_parameters": {"add": 2}}}, @@ -575,6 +575,17 @@ class TestPipeline: err.match(r"Component .+ not imported.") + def test_from_dict_with_invalid_type(self): + data = { + "metadata": {"test": "test"}, + "components": {"add_two": {"type": "", "init_parameters": {"add": 2}}}, + "connections": [], + } + with pytest.raises(PipelineError) as err: + Pipeline.from_dict(data) + + err.match(r"Component '' \(name: 'add_two'\) not imported.") + # UNIT def test_from_dict_without_connection_sender(self): data = {"metadata": {"test": "test"}, "components": {}, "connections": [{"receiver": "some.receiver"}]}