diff --git a/src/promptflow-core/promptflow/core/_connection_provider/_dict_connection_provider.py b/src/promptflow-core/promptflow/core/_connection_provider/_dict_connection_provider.py index 407c80547b1..34877a35a76 100644 --- a/src/promptflow-core/promptflow/core/_connection_provider/_dict_connection_provider.py +++ b/src/promptflow-core/promptflow/core/_connection_provider/_dict_connection_provider.py @@ -106,7 +106,7 @@ def get(self, name: str) -> Any: connection = self._connections.get(name) if not connection: raise ConnectionNotFound( - f"Connection {name!r} not found in dict connection provider." + f"Connection {name!r} not found in dict connection provider. " f"Available keys are {list(self._connections.keys())}." ) return connection diff --git a/src/promptflow-core/promptflow/executor/_errors.py b/src/promptflow-core/promptflow/executor/_errors.py index 2143511d9e6..ffd29f4389b 100644 --- a/src/promptflow-core/promptflow/executor/_errors.py +++ b/src/promptflow-core/promptflow/executor/_errors.py @@ -55,7 +55,20 @@ def __init__( class GetConnectionError(InvalidRequest): - pass + def __init__( + self, + connection: str, + node_name: str, + error: Exception, + **kwargs, + ): + super().__init__( + message_format="Get connection '{connection}' for node '{node_name}' error: {error}", + connection=connection, + node_name=node_name, + error=str(error), + target=ErrorTarget.EXECUTOR, + ) class InvalidBulkTestRequest(ValidationException): diff --git a/src/promptflow-core/promptflow/executor/_tool_resolver.py b/src/promptflow-core/promptflow/executor/_tool_resolver.py index 5fd39aa7f73..fec9d90f3dd 100644 --- a/src/promptflow-core/promptflow/executor/_tool_resolver.py +++ b/src/promptflow-core/promptflow/executor/_tool_resolver.py @@ -87,7 +87,7 @@ def _convert_to_connection_value(self, k: str, v: InputAssignment, node_name: st connection_value = self._connection_provider.get(v.value) except Exception as e: # Cache all exception as different provider raises different exceptions # Raise new error with node details - raise GetConnectionError(f"Connection {v.value} for node {node_name!r} input {k!r} error: {str(e)}.") from e + raise GetConnectionError(v.value, node_name, e) from e # Check if type matched if not any(type(connection_value).__name__ == typ for typ in conn_types): msg = ( @@ -114,7 +114,7 @@ def _convert_to_custom_strong_type_connection_value( connection_value = self._connection_provider.get(v.value) except Exception as e: # Cache all exception as different provider raises different exceptions # Raise new error with node details - raise GetConnectionError(f"Connection {v.value} for node {node_name!r} input {k!r} error: {str(e)}.") from e + raise GetConnectionError(v.value, node_name, e) from e custom_defined_connection_class_name = conn_types[0] source_type = getattr(source, "type", None) @@ -486,7 +486,7 @@ def _get_llm_node_connection(self, node: Node): connection = self._connection_provider.get(node.connection) except Exception as e: # Cache all exception as different provider raises different exceptions # Raise new error with node details - raise GetConnectionError(f"Connection {node.connection} for node {node.name!r} error: {str(e)}.") from e + raise GetConnectionError(node.connection, node.name, e) from e return connection @staticmethod diff --git a/src/promptflow/tests/executor/e2etests/test_executor_happypath.py b/src/promptflow/tests/executor/e2etests/test_executor_happypath.py index 59fd93a8500..481856bad31 100644 --- a/src/promptflow/tests/executor/e2etests/test_executor_happypath.py +++ b/src/promptflow/tests/executor/e2etests/test_executor_happypath.py @@ -191,7 +191,10 @@ def test_executor_node_overrides(self, dev_connections): raise_ex=True, ) assert isinstance(e.value.inner_exception, GetConnectionError) - assert "Connection 'dummy_connection' of LLM node 'classify_with_llm' is not found." in str(e.value) + assert ( + "Get connection 'dummy_connection' for node 'classify_with_llm' " + "error: Connection 'dummy_connection' not found" in str(e.value) + ) @pytest.mark.parametrize( "flow_folder",