Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Structured error handling for the Java SDK
Summary
This PR adds structured, typed error handling for errors originating from the SurrealDB server. Callers can catch specific exception types, inspect machine-readable error kinds and details, and walk the server-side cause chain when errors are nested.
What's included
Exception hierarchy
SurrealException— Base for all SDK errors (replaces the previous generic exception where applicable).ServerException— Base for errors returned by the server. Exposes:getKindEnum()— Error kind as an enum for type-safe matching (aligned with the Rust SDK’sErrorDetails).getKind()— Machine-readable kind string (for unknown kinds or when the raw wire value is needed).getDetails()— Optional structured payload (e.g. which table was not found, auth variant).getServerCause()— The next server error in the chain, if any.ValidationException,ConfigurationException,ThrownException,QueryException,SerializationException,NotAllowedException,NotFoundException,AlreadyExistsException,InternalException. Unknown kinds surface asServerExceptionfor forward compatibility.Convenience API
ErrorKind— Java enum aligned with the Rust SDK’sErrorDetailsvariants (VALIDATION,NOT_FOUND,NOT_ALLOWED, etc.). Passed across the JNI boundary so the Java SDK relies on the Rust SDK for deserialization and variant mapping.NotFoundDetailKind.TABLE,AuthDetailKind.TOKEN_EXPIRED, for use with the detail helpers.NotFoundException.getTableName(),NotFoundException.getRecordId(),NotAllowedException.isTokenExpired(),QueryException.getTimeout(), so callers can work with typed details without parsinggetDetails()by hand.hasKind(ErrorKind)/hasKind(String),findCause(ErrorKind)/findCause(String)to traverse the chain and find a specific error kind.Detail format
Details follow the SurrealDB wire format: a
kindand optional nesteddetails. The Java helpers support both the current internally-tagged format and the legacy externally-tagged format for compatibility with older servers. Subclass getters and the shared helpers (detailKind,detailField,getDetailString, etc.) work with both.Native integration
The Rust/JNI layer matches on the Rust SDK’s
ErrorDetailsenum (fromerror.details()) to choose the Java exception class and theErrorKindenum constant. It passesErrorKindacross the boundary (with an optional raw kind string for unknown variants), builds the cause chain from the error source chain, and converts typed details to Java objects (Map/String/Number) so the Java side receives a ready-to-use object tree without JSON parsing.Testing
THROWstatements) produce the expected exception types and details.