gofr-dev/gofr · error
client not connected, call Connect() first
Error message
client not connected, call Connect() first
What it means
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.
Source
Thrown at pkg/gofr/datasource/kv-store/dynamodb/dynamo.go:19
package dynamodb
import (
"context"
"encoding/json"
"errors"
"fmt"
"time"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
)
var (
errClientNotConnected = errors.New("client not connected, call Connect() first")
errKeyNotFound = errors.New("key not found")
errStatusDown = errors.New("status down")
)
type Configs struct {
Table string
Region string
Endpoint string
PartitionKeyName string
}
type dynamoDBInterface interface {
PutItem(
ctx context.Context,
params *dynamodb.PutItemInput,
optFns ...func(*dynamodb.Options),
) (*dynamodb.PutItemOutput, error)
GetItem(
ctx context.Context,View on GitHub (pinned to 187eb24962)
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
Example fix
// before
client := &dynamo.Client{}
client.Get(ctx, "key") // not connected
// after
client := &dynamo.Client{}
if err := client.Connect(cfg); err != nil {
return err
}
client.Get(ctx, "key") Defensive patterns
Strategy: validation
Validate before calling
if client == nil || !client.connected {
return errors.New("dynamo client not initialized; call Connect()")
}
client.Get(ctx, key) Type guard
func isConnected(c *dynamo.Client) bool {
return c != nil // plus internal connected flag if exposed
} Try / catch
if err := client.Set(ctx, k, v); err != nil {
if err.Error() == "client not connected, call Connect() first" {
_ = client.Connect(cfg)
err = client.Set(ctx, k, v)
}
return err
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- File is closed
- status down
- key not found
- failed to marshal value to JSON: %w
- failed to unmarshal JSON: %w
AI-assisted analysis of gofr-dev/gofr@187eb24962 (2026-09-01).
Data as JSON: /api/errors/d3a6de10fa2c6d79.
Report an issue: GitHub.