{"record":{"id":"d3a6de10fa2c6d79","repo":"gofr-dev/gofr","slug":"client-not-connected-call-connect-first","errorCode":null,"errorMessage":"client not connected, call Connect() first","messagePattern":"client not connected, call Connect\\(\\) first","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gofr/datasource/kv-store/dynamodb/dynamo.go","lineNumber":19,"sourceCode":"package dynamodb\n\nimport (\n\t\"context\"\n\t\"encoding/json\"\n\t\"errors\"\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/aws/aws-sdk-go-v2/aws\"\n\t\"github.com/aws/aws-sdk-go-v2/config\"\n\t\"github.com/aws/aws-sdk-go-v2/service/dynamodb\"\n\t\"github.com/aws/aws-sdk-go-v2/service/dynamodb/types\"\n\t\"go.opentelemetry.io/otel/attribute\"\n\t\"go.opentelemetry.io/otel/trace\"\n)\n\nvar (\n\terrClientNotConnected = errors.New(\"client not connected, call Connect() first\")\n\terrKeyNotFound        = errors.New(\"key not found\")\n\terrStatusDown         = errors.New(\"status down\")\n)\n\ntype Configs struct {\n\tTable            string\n\tRegion           string\n\tEndpoint         string\n\tPartitionKeyName string\n}\ntype dynamoDBInterface interface {\n\tPutItem(\n\t\tctx context.Context,\n\t\tparams *dynamodb.PutItemInput,\n\t\toptFns ...func(*dynamodb.Options),\n\t) (*dynamodb.PutItemOutput, error)\n\tGetItem(\n\t\tctx context.Context,","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/gofr-dev/gofr/blob/187eb24962502e91f1fee856230670958b66e89c/pkg/gofr/datasource/kv-store/dynamodb/dynamo.go#L1-L37","documentation":"errClientNotConnected is returned by the DynamoDB kv-store client's Get, Set, Delete, Subscribe, Publish, and Query methods when the client has not been initialized via Connect(). The client guards every operation so calls before connection fail fast with this message instead of nil-pointer panics.","triggerScenarios":"Calling any store method (Get/Set/Delete/Query/Publish/Subscribe) before Connect() was called, or after Close() without reconnecting; Connect() failing silently and code proceeding anyway.","commonSituations":"Forgetting Connect in setup; connection deferred to a goroutine while requests arrive; app restarts where Close ran but handlers still reference the old client; test fixtures that skip Connect.","solutions":["Call client.Connect(config) before any operation","Check the connection state / add errors.Is(err, errClientNotConnected) handling","Ensure Close is only called at shutdown and clients are re-created afterwards","Await successful Connect (or readiness check) before serving traffic"],"exampleFix":"// before\nclient := &dynamo.Client{}\nclient.Get(ctx, \"key\") // not connected\n// after\nclient := &dynamo.Client{}\nif err := client.Connect(cfg); err != nil {\n    return err\n}\nclient.Get(ctx, \"key\")","handlingStrategy":"validation","validationCode":"if client == nil || !client.connected {\n    return errors.New(\"dynamo client not initialized; call Connect()\")\n}\nclient.Get(ctx, key)","typeGuard":"func isConnected(c *dynamo.Client) bool {\n    return c != nil // plus internal connected flag if exposed\n}","tryCatchPattern":"if err := client.Set(ctx, k, v); err != nil {\n    if err.Error() == \"client not connected, call Connect() first\" {\n        _ = client.Connect(cfg)\n        err = client.Set(ctx, k, v)\n    }\n    return err\n}","preventionTips":["Always call Connect() during app initialization before serving requests","Await successful Connect with a readiness barrier","Re-create/reconnect clients after Close()","Add startup integration test that performs a Get after Connect"],"tags":["dynamodb","kv-store","lifecycle","initialization","gofr"],"backgroundTag":"client-not-connected","analyzedSha":"187eb24962502e91f1fee856230670958b66e89c","analyzedAt":"2026-09-01T20:34:54.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}