Skip to content

v6: Throw WeaviateApiException for error status codes #437

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

Merged
merged 10 commits into from
Aug 13, 2025
Merged

Conversation

bevzzz
Copy link
Collaborator

@bevzzz bevzzz commented Aug 4, 2025

Closes #403

This PR adds explicit error handling logic to the HTTP and gRPC transport. Previously both would either "swallow" a bad status code entirely or leak the internals by throwing something like io.grpc.StatusRuntimeException, which made error handling difficult or, at times, impossible.

While error handling is transparent in the sense that both gRPC and HTTP transports throw the same WeaviateApiException, users may still encounter an IOException thrown by the HTTP transport. At the moment we do not catch/wrap it, because those errors would not be Weaviate-specific (e.g. timeout, connection reset by peer, etc) and are better handled separately.

💡 WeaviateException is the base class for handling any Weaviate-related exceptions. It's useful when we only want to log/propagate the exception.

HTTP requests

var things = client.collections.use("Things");

try {
  things.data.insert(Map.of("title", "Red balloon"), thing -> thing.uuid("invalid"));
} catch (WeaviateApiException e) {
  System.out.println(e.getMessage());
  // Outputs: HTTP 422, POST /v1/objects: id "invalid" is not a valid UUID
}

gRPC Requests

var things = client.collections.use("Things");

try {
  things.query.bm25("red balloon", q -> q.returnProperties("unknown"));
} catch (WeaviateApiException e) {
  System.out.println(e.getMessage());
  // Outputs: UNKNOWN: class Things does not have property "unknown"
}

Pagination

WeaviatePaginationException preserves information about the pageSize and the last cursor used. The original exception is accessible via e.getCause() (can be WeaviateApiException or some other IOException).

var unknown = client.collections.use("Unknown");

String lastCursor;
try {
  unknown.paginate().forEach(System.out::println);
} catch (WeaviatePaginationException e) {
    lastCursor = e.cursor();
}

Endpoint utility classes

Inspired by Elasticsearch's Endpoint pattern, the new SimpleEndpoint, OptionalEndpoint, and BinaryEndpoint reduce boilerplate in how HTTP requests are defined.

Removed deprecated vectorizeClassName parameter

Using this parameter is highly discouraged. We remove it from all vectorizers but one, text2vec-contextionary, because Weaviate will default to true, which does not allow creating collections with underscores in their names. That's annoying, so we make it read-only in the public API and always send false in the request.

Copy link

@orca-security-eu orca-security-eu bot left a comment

Choose a reason for hiding this comment

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

Orca Security Scan Summary

Status Check Issues by priority
Passed Passed Secrets high 0   medium 0   low 0   info 0 View in Orca

@bevzzz bevzzz force-pushed the v6-error-handling branch from b7e9579 to 3256405 Compare August 5, 2025 14:19
@bevzzz bevzzz marked this pull request as ready for review August 5, 2025 14:47
@bevzzz bevzzz self-assigned this Aug 5, 2025
@bevzzz bevzzz linked an issue Aug 5, 2025 that may be closed by this pull request
@bevzzz bevzzz force-pushed the v6-error-handling branch from 536a43d to 5dc3a1c Compare August 6, 2025 18:31
@bevzzz bevzzz merged commit 71af20b into v6 Aug 13, 2025
2 checks passed
@bevzzz bevzzz deleted the v6-error-handling branch August 13, 2025 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error handling and error propagation
1 participant