{"record":{"id":"c5480f9c8a8f9c3e","repo":"gofr-dev/gofr","slug":"unexpected-result-type-expected-any","errorCode":null,"errorMessage":"unexpected result type: expected []any","messagePattern":"unexpected result type: expected \\[\\]any","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gofr/datasource/surrealdb/surrealdb.go","lineNumber":23,"sourceCode":"\t\"errors\"\n\t\"fmt\"\n\t\"math\"\n\t\"strings\"\n\t\"time\"\n\n\t\"github.com/surrealdb/surrealdb.go\"\n\t\"github.com/surrealdb/surrealdb.go/pkg/models\"\n\t\"go.opentelemetry.io/otel/attribute\"\n\t\"go.opentelemetry.io/otel/trace\"\n)\n\nvar (\n\terrNotConnected             = errors.New(\"not connected to database\")\n\terrNoDatabaseInstance       = errors.New(\"failed to connect to SurrealDB: no valid database instance\")\n\terrInvalidCredentialsConfig = errors.New(\"both username and password must be provided\")\n\terrNoRecord                 = errors.New(\"no record found\")\n\terrNoResult                 = errors.New(\"no result found in query response\")\n\terrUnexpectedResult         = errors.New(\"unexpected result type: expected []any\")\n\terrQueryError               = errors.New(\"query error\")\n)\n\nconst (\n\tschemeHTTP      = \"http\"\n\tschemeHTTPS     = \"https\"\n\tschemeWS        = \"ws\"\n\tschemeWSS       = \"wss\"\n\tschemeMemory    = \"memory\"\n\tschemeMem       = \"mem\"\n\tschemeSurrealkv = \"surrealkv\"\n\tstatusOK        = \"OK\"\n\n\tdefaultTimeout = 30 * time.Second\n)\n\n// Config represents the configuration required to connect to SurrealDB.\ntype Config struct {","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/gofr-dev/gofr/blob/187eb24962502e91f1fee856230670958b66e89c/pkg/gofr/datasource/surrealdb/surrealdb.go#L5-L41","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nrequire github.com/surrealdb/surrealdb.go v0.3.0 // mismatched response shape\n// after\nrequire github.com/surrealdb/surrealdb.go v0.5.1 // version gofr expects","handlingStrategy":"retry","validationCode":null,"typeGuard":"func isUnexpectedResult(err error) bool { return errors.Is(err, surrealdb.ErrUnexpectedResult) }","tryCatchPattern":"rec, err := client.Create(ctx, table, data)\nif errors.Is(err, surrealdb.ErrUnexpectedResult) {\n    // log raw response shape, check SDK/server versions, do not retry blindly\n    return fmt.Errorf(\"response shape mismatch (check SDK version): %w\", err)\n}","preventionTips":["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."],"tags":["surrealdb","type-mismatch","compatibility"],"backgroundTag":"unexpected-response-type","analyzedSha":"187eb24962502e91f1fee856230670958b66e89c","analyzedAt":"2026-09-01T20:34:54.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}