{"record":{"id":"45419f067bd629a9","repo":"gofr-dev/gofr","slug":"no-result-found-in-query-response","errorCode":null,"errorMessage":"no result found in query response","messagePattern":"no result found in query response","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/gofr/datasource/surrealdb/surrealdb.go","lineNumber":22,"sourceCode":"\t\"context\"\n\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.","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/gofr-dev/gofr/blob/187eb24962502e91f1fee856230670958b66e89c/pkg/gofr/datasource/surrealdb/surrealdb.go#L4-L40","documentation":"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.","triggerScenarios":"Calling client.Query with a SELECT/SurrealQL statement whose result set is empty (no matching rows, wrong table, or filters excluding everything).","commonSituations":"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.","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."],"exampleFix":"// before\nres, err := client.Query(ctx, \"SELECT * FROM user WHERE id = $id\")\n// panics on empty result\n// after\nres, err := client.Query(ctx, \"SELECT * FROM user WHERE id = $id\")\nif errors.Is(err, surrealdb.ErrNoResult) { return nil, ErrUserNotFound }","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"func isNoResult(err error) bool { return errors.Is(err, surrealdb.ErrNoResult) }","tryCatchPattern":"res, err := client.Query(ctx, q)\nswitch {\ncase errors.Is(err, surrealdb.ErrNoResult):\n    return nil, ErrNotFound // treat as empty result, not a failure\ncase err != nil:\n    return nil, err\n}","preventionTips":["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."],"tags":["surrealdb","query","empty-result"],"backgroundTag":"no-rows-returned","analyzedSha":"187eb24962502e91f1fee856230670958b66e89c","analyzedAt":"2026-09-01T20:34:54.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}