{"record":{"id":"a0cc9008321f0d2e","repo":"gofr-dev/gofr","slug":"not-connected-to-database","errorCode":null,"errorMessage":"not connected to database","messagePattern":"not connected to database","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gofr/datasource/surrealdb/surrealdb.go","lineNumber":18,"sourceCode":"package surrealdb\n\nimport (\n\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","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/gofr-dev/gofr/blob/187eb24962502e91f1fee856230670958b66e89c/pkg/gofr/datasource/surrealdb/surrealdb.go#L1-L36","documentation":"errNotConnected is returned by the SurrealDB client's query-facing methods (Chat, Embed, Stream, and other operations) when the client has no live database instance — i.e. Connect was never called, failed, or the connection was closed. gofr guards every operation with an internal client nil/liveness check.","triggerScenarios":"Calling client.Chat, client.Embed, or client.Stream before client.Connect succeeds, after Connect returns an error that was ignored, or after the SurrealDB instance was closed/reset.","commonSituations":"Using a client returned from a failed Connect, constructing the client directly without connecting, SurrealDB server down at startup so Connect failed, or reusing a client across lifecycle resets.","solutions":["Call client.Connect and check its error before issuing any Chat/Embed/Stream calls.","Verify SurrealDB is reachable (URL/provider config) so Connect succeeds.","Recreate or reconnect the client if it was closed or previously failed."],"exampleFix":"// before\nclient := surrealdb.New(cfg)\nclient.Chat(ctx, req) // not connected\n// after\nclient := surrealdb.New(cfg)\nif err := client.Connect(ctx); err != nil { log.Fatal(err) }\nresp, err := client.Chat(ctx, req)","handlingStrategy":"try-catch","validationCode":"if !client.IsConnected() { // or check connect error first\n    if err := client.Connect(ctx); err != nil { return err }\n}","typeGuard":null,"tryCatchPattern":"resp, err := client.Chat(ctx, req)\nif errors.Is(err, surrealdb.ErrNotConnected) {\n    if cerr := client.Connect(ctx); cerr != nil { return cerr }\n    resp, err = client.Chat(ctx, req)\n}","preventionTips":["Always check the error returned by Connect before using query methods.","Centralize client construction in an init function that fails fast.","Reconnect on lifecycle events (close, reset) instead of reusing stale clients."],"tags":["surrealdb","connection","lifecycle"],"backgroundTag":"not-connected","analyzedSha":"187eb24962502e91f1fee856230670958b66e89c","analyzedAt":"2026-09-01T20:34:54.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}