gofr-dev/gofr · warning
no result found in query response
Error message
no result found in query response
What it means
errNoResult is returned by Query when the SurrealDB query executes successfully but the response array is empty — gofr guarantees callers a result element and surfaces this sentinel when the query returned none. It distinguishes "query ran, no rows" from query errors.
Source
Thrown at pkg/gofr/datasource/surrealdb/surrealdb.go:22
"context"
"errors"
"fmt"
"math"
"strings"
"time"
"github.com/surrealdb/surrealdb.go"
"github.com/surrealdb/surrealdb.go/pkg/models"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
)
var (
errNotConnected = errors.New("not connected to database")
errNoDatabaseInstance = errors.New("failed to connect to SurrealDB: no valid database instance")
errInvalidCredentialsConfig = errors.New("both username and password must be provided")
errNoRecord = errors.New("no record found")
errNoResult = errors.New("no result found in query response")
errUnexpectedResult = errors.New("unexpected result type: expected []any")
errQueryError = errors.New("query error")
)
const (
schemeHTTP = "http"
schemeHTTPS = "https"
schemeWS = "ws"
schemeWSS = "wss"
schemeMemory = "memory"
schemeMem = "mem"
schemeSurrealkv = "surrealkv"
statusOK = "OK"
defaultTimeout = 30 * time.Second
)
// Config represents the configuration required to connect to SurrealDB.View on GitHub (pinned to 187eb24962)
Solutions
- Handle the empty result: check errors.Is(err, surrealdb.ErrNoResult) and treat it as "no data" rather than a crash.
- Verify the table contains data (run the query directly in SurrealDB shell).
- Relax or correct WHERE/filters and fix table name typos.
Example fix
// before
res, err := client.Query(ctx, "SELECT * FROM user WHERE id = $id")
// panics on empty result
// after
res, err := client.Query(ctx, "SELECT * FROM user WHERE id = $id")
if errors.Is(err, surrealdb.ErrNoResult) { return nil, ErrUserNotFound } Defensive patterns
Strategy: type-guard
Type guard
func isNoResult(err error) bool { return errors.Is(err, surrealdb.ErrNoResult) } Try / catch
res, err := client.Query(ctx, q)
switch {
case errors.Is(err, surrealdb.ErrNoResult):
return nil, ErrNotFound // treat as empty result, not a failure
case err != nil:
return nil, err
} Prevention
- Always handle ErrNoResult explicitly in query wrappers.
- Verify table names and seed data before querying in new environments.
- Add integration tests that exercise queries against seeded fixtures.
When it happens
Trigger: Calling client.Query with a SELECT/SurrealQL statement whose result set is empty (no matching rows, wrong table, or filters excluding everything).
Common situations: Querying a table that has no data yet, WHERE clauses that match nothing, typos in table names, or expecting seed data that was never inserted.
Related errors
- query error
- not connected to database
- failed to connect to SurrealDB: no valid database instance
- both username and password must be provided
- no record found
AI-assisted analysis of gofr-dev/gofr@187eb24962 (2026-09-01).
Data as JSON: /api/errors/45419f067bd629a9.
Report an issue: GitHub.