{"record":{"id":"9f94094da833c205","repo":"gofr-dev/gofr","slug":"key-not-found","errorCode":null,"errorMessage":"key not found","messagePattern":"key not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/gofr/datasource/kv-store/dynamodb/dynamo.go","lineNumber":20,"sourceCode":"\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,\n\t\tparams *dynamodb.GetItemInput,","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/gofr-dev/gofr/blob/187eb24962502e91f1fee856230670958b66e89c/pkg/gofr/datasource/kv-store/dynamodb/dynamo.go#L2-L38","documentation":"errKeyNotFound is the sentinel error ('key not found') declared in the DynamoDB KV-store client and returned by Get and Delete when the requested key has no entry in the configured DynamoDB table. The Get implementation wraps it with the key name using %w, so callers can detect it with errors.Is(err, errKeyNotFound). It is a normal, expected condition rather than a fault in the client.","triggerScenarios":"Calling Client.Get(ctx, key) on a key that was never Set, was Delete'd, or whose item lacks the 'value' attribute in the table; calling Delete with a non-existent key; querying the wrong table or wrong AWS region so the key appears missing.","commonSituations":"Typos or casing differences in keys, pointing Configs.Table at a stale or different table, reading before an initial Set (e.g. cache-miss logic), keys removed by TTL or by another process.","solutions":["Check errors.Is(err, datasource/.../dynamodb errKeyNotFound) and treat it as a miss, then Set or fall back","Verify Configs.Table and Configs.Region point to the table/region where the key was written","Confirm the key was Set successfully before Get (check Set's returned error)","Use consistent key naming (constant or helper) to avoid typos/case mismatches"],"exampleFix":"// before\nval, err := store.Get(ctx, \"user:42\")\nif err != nil { return err }\n// after\nval, err := store.Get(ctx, \"user:42\")\nif errors.Is(err, dynamodb.ErrKeyNotFound) {\n    val = defaultUser // handle miss gracefully\n} else if err != nil { return err }","handlingStrategy":"fallback","validationCode":"// ensure table configured before use\nif cfg.Table == \"\" || cfg.Region == \"\" { return errors.New(\"dynamodb KV not configured\") }","typeGuard":"func IsKeyNotFound(err error) bool { return errors.Is(err, dynamodb.ErrKeyNotFound) }","tryCatchPattern":"v, err := store.Get(ctx, key)\nswitch {\ncase errors.Is(err, dynamodb.ErrKeyNotFound): v = missValue(key)\ncase err != nil: return err\n}","preventionTips":["Always branch on errors.Is(err, ErrKeyNotFound) before generic error handling","Keep a single key-builder helper to avoid typos/case mismatches","Verify table/region config in an init/connect step","Treat misses as normal flow (cache-miss pattern), not crashes"],"tags":["dynamodb","kv-store","key-not-found","aws"],"backgroundTag":"key-not-found","analyzedSha":"187eb24962502e91f1fee856230670958b66e89c","analyzedAt":"2026-09-01T20:34:54.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}