Skip to content

Add support for SurrealDB v3 structured error handling#382

Merged
mumoshu merged 3 commits intomainfrom
surrealdb-v3-structured-err
Mar 3, 2026
Merged

Add support for SurrealDB v3 structured error handling#382
mumoshu merged 3 commits intomainfrom
surrealdb-v3-structured-err

Conversation

@mumoshu
Copy link
Contributor

@mumoshu mumoshu commented Mar 2, 2026

Introduce ServerError for SurrealDB v3 structured errors while preserving backward compatibility with the existing RPCError and QueryError types.

Keep using RPCError in SurrealDB v2 (although we recommend upgrading to v3, and' RPCError' has been deprecated to signal that).

Use ServerError on SurrealDB v3.

Errors embedded inside QueryResult remain as QueryError.

_, err := surrealdb.Select[map[string]any](context.Background(), db,
	models.Table("nonexistent_table_for_test"),
)

// Use it on SurrealDB v3 only
var se surrealdb.ServerError
if errors.As(err, &se) {
	// Get access to new error fields like Kind, Details, and Cause
}

// You can also use this idiom to obtain the cause
var cause surrealdb.ServerError
if errors.As(errors.Unwrap(se), &cause) {
	// Get access Kind, Details, and Cause of Cause
}

Based on #380

Introduce ServerError type for SurrealDB v3 structured errors (Kind,
Details, Cause) while preserving backward compatibility with the
existing RPCError and QueryError types.

```go
_, err := surrealdb.Select[map[string]any](context.Background(), db,
	models.Table("nonexistent_table_for_test"),
)

// Use ServerError on SurrealDB v3
var se surrealdb.ServerError
if errors.As(err, &se) {
	// Get access to new error fields like Kind, Details and Cause
}
```
@mumoshu mumoshu force-pushed the surrealdb-v3-structured-err branch from 0c4d1fc to 22ca69f Compare March 2, 2026 12:54
@mumoshu
Copy link
Contributor Author

mumoshu commented Mar 3, 2026

Thanks for your contribution, @kearfy!

@mumoshu mumoshu merged commit a7bf54b into main Mar 3, 2026
21 checks passed
@mumoshu mumoshu deleted the surrealdb-v3-structured-err branch March 3, 2026 07:26
@mumoshu mumoshu mentioned this pull request Mar 3, 2026
10 tasks
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.

2 participants