Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Third party errors #1357

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions weaviate/collections/classes/internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
from weaviate.util import _to_beacons
from weaviate.types import INCLUDE_VECTOR, UUID, UUIDS

from weaviate.proto.v1 import search_get_pb2
from weaviate.proto.v1 import search_get_pb2, generative_pb2


@dataclass
Expand Down Expand Up @@ -208,8 +208,8 @@ def __init__(
self.grouped = grouped
self.grouped_properties = grouped_properties

def to_grpc(self) -> search_get_pb2.GenerativeSearch:
return search_get_pb2.GenerativeSearch(
def to_grpc(self) -> generative_pb2.GenerativeSearch:
return generative_pb2.GenerativeSearch(
single_response_prompt=self.single,
grouped_response_task=self.grouped,
grouped_properties=self.grouped_properties,
Expand Down
14 changes: 13 additions & 1 deletion weaviate/collections/grpc/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
WeaviateQueryError,
WeaviateUnsupportedFeatureError,
WeaviateInvalidInputError,
WeaviateQueryThirdPartyError,
)
from weaviate.proto.v1 import search_get_pb2
from weaviate.types import NUMBER, UUID
Expand Down Expand Up @@ -759,6 +760,7 @@ def __create_request(
return search_get_pb2.SearchRequest(
uses_123_api=True,
uses_125_api=self.__uses_125_api,
uses_128_api=True, # sets a new return format for errors. The client can handle both
collection=self._name,
limit=limit,
offset=offset,
Expand Down Expand Up @@ -800,7 +802,17 @@ async def __call(self, request: search_get_pb2.SearchRequest) -> search_get_pb2.
metadata=self._connection.grpc_headers(),
timeout=self._connection.timeout_config.query,
)
return cast(search_get_pb2.SearchReply, res)
sr = cast(search_get_pb2.SearchReply, res)
if sr.third_party_error is not None and sr.third_party_error.provider_name != "":
raise WeaviateQueryThirdPartyError(
sr.third_party_error.full_error,
sr.third_party_error.provider_name,
sr.third_party_error.error_from_provider,
sr.third_party_error.status_code,
sr.third_party_error.request_id,
"GRPC search",
)
return sr
except AioRpcError as e:
raise WeaviateQueryError(str(e), "GRPC search") # pyright: ignore

Expand Down
36 changes: 33 additions & 3 deletions weaviate/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,45 @@ def __init__(self, message: str):
class WeaviateQueryError(WeaviateBaseError):
"""Is raised if a query (either gRPC or GraphQL) to Weaviate fails in any way."""

def __init__(self, message: str, protocol_type: str):
msg = f"""Query call with protocol {protocol_type} failed with message {message}."""
def __init__(self, message: str, protocol_type: str, add_message: bool = True):
if add_message:
msg = f"""Query call with protocol {protocol_type} failed with message {message}."""
else:
msg = message
super().__init__(msg)
self.message = message
self.message = msg


WeaviateQueryException = WeaviateQueryError


class WeaviateQueryThirdPartyError(WeaviateQueryError):
"""Is raised if a query (either gRPC or GraphQL) to Weaviate fails in any way."""

def __init__(
self,
full_error: str,
provider_name: str,
provider_error: str,
error_code: int,
request_id: str,
protocol_type: str,
):
request_id_str = f"with request_id {request_id} " if request_id else ""

msg = f"""
Full error message: {full_error}

Query {request_id_str}failed due to an error with a third party service:
Provider: {provider_name}
Error code: {error_code}
Error from provider: {provider_error}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copyedit suggestion: Wdyt about:

msg = f"""Query {request_id_str} failed:

Provider ({provider_name}) service error {error_code}.

Error details:

{'Provider:':>25} {provider_name}
{'Provider error code:':>25} {error_code}
{'Provider message:':>25} {provider_error}

Weaviate error message:

{full_error}"""

Mainly to really clarify what part of the message comes from the provider? (Also for right-aligning the structured part, which - not important either way)

"""
super().__init__(msg, protocol_type, False)
self.message = msg


class WeaviateBatchError(WeaviateQueryError):
"""Is raised if a gRPC batch query to Weaviate fails in any way."""

Expand Down
121 changes: 121 additions & 0 deletions weaviate/proto/v1/generative_pb2.py

Large diffs are not rendered by default.

Loading
Loading