gofr-dev/gofr · error
unexpected result type: expected []any
Error message
unexpected result type: expected []any
What it means
errUnexpectedResult is returned by extractRecord when the raw SurrealDB response has an unexpected dynamic type — gofr expects []any (a slice of results) but the SDK returned something else (e.g. a map, nil, or a scalar). It indicates a shape mismatch between what the SDK handed back and what gofr's extraction logic supports.
Source
Thrown at pkg/gofr/datasource/surrealdb/surrealdb.go:23
"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.
type Config struct {View on GitHub (pinned to 187eb24962)
Solutions
- Align the surrealdb.go SDK version with the one gofr was built against (go.mod / go get surrealdb@compatible).
- Inspect the raw query response to see its actual shape and adjust the query to return an array.
- Check SurrealDB server version compatibility — newer servers may change result encoding.
- If persistent, report/patch the extraction logic for the response shape you receive.
Example fix
// before require github.com/surrealdb/surrealdb.go v0.3.0 // mismatched response shape // after require github.com/surrealdb/surrealdb.go v0.5.1 // version gofr expects
Defensive patterns
Strategy: retry
Type guard
func isUnexpectedResult(err error) bool { return errors.Is(err, surrealdb.ErrUnexpectedResult) } Try / catch
rec, err := client.Create(ctx, table, data)
if errors.Is(err, surrealdb.ErrUnexpectedResult) {
// log raw response shape, check SDK/server versions, do not retry blindly
return fmt.Errorf("response shape mismatch (check SDK version): %w", err)
} Prevention
- Pin surrealdb.go SDK version to one gofr is tested against.
- Test against your actual SurrealDB server version in CI.
- Log raw SDK responses when upgrading either library to catch shape changes early.
When it happens
Trigger: Calling Create/Update/Query paths that route through extractRecord where the SurrealDB SDK returns a non-slice payload — e.g. a single-object response, an error object encoded as a result, or an SDK version whose return type changed.
Common situations: Version drift between the surrealdb.go SDK and gofr's expected response shape, SurrealDB server returning an error payload in the result field, or direct queries whose result is a single object rather than an array.
Related errors
- operations cannot be empty
- elasticsearch operation error
- input should be a pointer to a string
- not connected to database
- failed to connect to SurrealDB: no valid database instance
AI-assisted analysis of gofr-dev/gofr@187eb24962 (2026-09-01).
Data as JSON: /api/errors/c5480f9c8a8f9c3e.
Report an issue: GitHub.