Skip to content

Commit

Permalink
feat: change PipelineConfigError to DocumentStoreError with more deta…
Browse files Browse the repository at this point in the history
  • Loading branch information
julian-risch authored Jan 2, 2023
1 parent 19c7725 commit b155297
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
10 changes: 7 additions & 3 deletions haystack/pipelines/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from haystack.pipelines.utils import generate_code, print_eval_report
from haystack.utils import DeepsetCloud, calculate_context_similarity
from haystack.schema import Answer, EvaluationResult, MultiLabel, Document, Span
from haystack.errors import HaystackError, PipelineError, PipelineConfigError
from haystack.errors import HaystackError, PipelineError, PipelineConfigError, DocumentStoreError
from haystack.nodes import BaseGenerator, Docs2Answers, BaseReader, BaseSummarizer, BaseTranslator, QuestionGenerator
from haystack.nodes.base import BaseComponent, RootNode
from haystack.nodes.retriever.base import BaseRetriever
Expand Down Expand Up @@ -2022,9 +2022,13 @@ def _load_or_get_component(cls, name: str, definitions: dict, components: dict):
f"Failed loading pipeline component '{name}': "
"seems like the component does not exist. Did you spell its name correctly?"
) from ke
except ConnectionError as ce:
raise DocumentStoreError(f"Failed loading pipeline component '{name}': '{ce}'") from ce
except DocumentStoreError as de:
raise de
except Exception as e:
raise PipelineConfigError(
f"Failed loading pipeline component '{name}'. " "See the stacktrace above for more informations."
f"Failed loading pipeline component '{name}'. See the stacktrace above for more information."
) from e

def save_to_yaml(self, path: Path, return_defaults: bool = False):
Expand Down Expand Up @@ -2152,7 +2156,7 @@ def _validate_node_names_in_params(self, params: Optional[Dict]):
not_a_node = set(params.keys()) - set(self.graph.nodes)
# "debug" will be picked up by _dispatch_run, see its code
# "add_isolated_node_eval" is set by pipeline.eval / pipeline.eval_batch
valid_global_params = set(["debug", "add_isolated_node_eval"])
valid_global_params = {"debug", "add_isolated_node_eval"}
for node_id in self.graph.nodes:
run_signature_args = self._get_run_node_signature(node_id)
valid_global_params |= set(run_signature_args)
Expand Down
42 changes: 41 additions & 1 deletion test/pipelines/test_pipeline_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from haystack import Pipeline
from haystack.nodes import _json_schema
from haystack.nodes import FileTypeClassifier
from haystack.errors import HaystackError, PipelineConfigError, PipelineSchemaError
from haystack.errors import HaystackError, PipelineConfigError, PipelineSchemaError, DocumentStoreError
from haystack.nodes.base import BaseComponent

from ..conftest import SAMPLES_PATH, MockNode, MockDocumentStore, MockReader, MockRetriever
Expand Down Expand Up @@ -141,6 +141,46 @@ def test_load_yaml(tmp_path):
assert isinstance(pipeline.get_node("reader"), MockReader)


def test_load_yaml_elasticsearch_not_responding(tmp_path):
# Test if DocumentStoreError is raised if elasticsearch instance is not responding (due to wrong port)
with open(tmp_path / "tmp_config.yml", "w") as tmp_file:
tmp_file.write(
f"""
version: ignore
components:
- name: ESRetriever
type: BM25Retriever
params:
document_store: DocumentStore
- name: DocumentStore
type: ElasticsearchDocumentStore
params:
port: 1234
- name: PDFConverter
type: PDFToTextConverter
- name: Preprocessor
type: PreProcessor
pipelines:
- name: query_pipeline
nodes:
- name: ESRetriever
inputs: [Query]
- name: indexing_pipeline
nodes:
- name: PDFConverter
inputs: [File]
- name: Preprocessor
inputs: [PDFConverter]
- name: ESRetriever
inputs: [Preprocessor]
- name: DocumentStore
inputs: [ESRetriever]
"""
)
with pytest.raises(DocumentStoreError):
Pipeline.load_from_yaml(path=tmp_path / "tmp_config.yml", pipeline_name="indexing_pipeline")


def test_load_yaml_non_existing_file():
with pytest.raises(FileNotFoundError):
Pipeline.load_from_yaml(path=SAMPLES_PATH / "pipeline" / "I_dont_exist.yml")
Expand Down

0 comments on commit b155297

Please sign in to comment.