gofr-dev/gofr · error

no record found

Error message

no record found

What it means

errNoRecord is returned by Create and Update on the SurrealDB client when the operation completes but the response contains no record — gofr expected the created/updated document back from SurrealDB and got an empty result. It indicates the write did not produce a returned record.

Source

Thrown at pkg/gofr/datasource/surrealdb/surrealdb.go:21

import (
	"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
)

View on GitHub (pinned to 187eb24962)

Solutions

  1. Verify the record ID/table exists before Update (query it first) and that Create uses a valid table name.
  2. Check SurrealDB permissions/auth allow the write for the connected user.
  3. Confirm the record ID format is correct (e.g. table:id via models.RecordID).
  4. Inspect the SurrealDB response/logs to see why no record was returned.

Example fix

// before
_, err := client.Update(ctx, "user:999", data) // record never existed
// after
rec, err := client.Create(ctx, "user", data)
// then update using the returned record's ID
Defensive patterns

Strategy: try-catch

Validate before calling

existing, qerr := client.Query(ctx, "SELECT * FROM user:999")
if qerr != nil && !errors.Is(qerr, surrealdb.ErrNoResult) { return qerr }

Try / catch

rec, err := client.Update(ctx, id, data)
if errors.Is(err, surrealdb.ErrNoRecord) {
    return fmt.Errorf("record %s does not exist: %w", id, err)
}

Prevention

When it happens

Trigger: Calling client.Create with a table/ID whose insert yields no stored document, or client.Update targeting a record ID that does not exist (SurrealDB returns no result for a missing record on update).

Common situations: Updating a record that was deleted by another writer, wrong record ID format (missing table prefix in the ID), permissions preventing the write so nothing is stored, or table-level rules dropping the insert.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of gofr-dev/gofr@187eb24962 (2026-09-01). Data as JSON: /api/errors/ed6c67fd31337850. Report an issue: GitHub.