{"record":{"id":"ba6d4f7e3ba9182d","repo":"gofr-dev/gofr","slug":"w-s-ba6d4f","errorCode":null,"errorMessage":"%w: %s","messagePattern":"%w: %s","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/gofr/datasource/kv-store/dynamodb/dynamo.go","lineNumber":174,"sourceCode":"\tout, err := c.db.GetItem(ctx, input)\n\tif err != nil {\n\t\tc.logger.Errorf(\"error while fetching data for key: %v, error: %v\", key, err)\n\t\treturn \"\", err\n\t}\n\n\tif out.Item == nil {\n\t\treturn \"\", errKeyNotFound\n\t}\n\n\t// Look for a \"value\" field that contains the JSON string\n\tif valueField, exists := out.Item[\"value\"]; exists {\n\t\tif stringValue, ok := valueField.(*types.AttributeValueMemberS); ok {\n\t\t\treturn stringValue.Value, nil\n\t\t}\n\t}\n\n\t// If no \"value\" field exists, return key not found error\n\treturn \"\", fmt.Errorf(\"%w: %s\", errKeyNotFound, key)\n}\n\nfunc (c *Client) Set(ctx context.Context, key, value string) error {\n\tif !c.connected {\n\t\treturn errClientNotConnected\n\t}\n\n\tspan := c.addTrace(ctx, \"set\", key)\n\tdefer c.sendOperationsStats(time.Now(), \"SET\", \"set\", span, key)\n\n\t// Store the value as a string in the \"value\" field\n\titem := map[string]types.AttributeValue{\n\t\tc.configs.PartitionKeyName: &types.AttributeValueMemberS{Value: key},\n\t\t\"value\":                    &types.AttributeValueMemberS{Value: value},\n\t}\n\n\tinput := &dynamodb.PutItemInput{\n\t\tTableName: aws.String(c.configs.Table),","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/gofr-dev/gofr/blob/187eb24962502e91f1fee856230670958b66e89c/pkg/gofr/datasource/kv-store/dynamodb/dynamo.go#L156-L192","documentation":"In the DynamoDB KV client, Get wraps errKeyNotFound with the offending key using fmt.Errorf(\"%w: %s\", errKeyNotFound, key) when the item exists but has no 'value' attribute, or more broadly when the key is absent. Because %w is used, errors.Is(err, errKeyNotFound) still matches. The message form is 'key not found: <key>'.","triggerScenarios":"Client.Get on a key whose DynamoDB item lacks a 'value' attribute (e.g. items written by other tools or with different attribute names), or on keys that do not exist in the table.","commonSituations":"Table populated by another application or migration using different attribute names, partially written items, wrong table selected, keys deleted concurrently.","solutions":["Check errors.Is(err, errKeyNotFound) and treat as a miss rather than a hard failure","Ensure writers use this client's Set so items contain the 'value' attribute","Verify Configs.Table targets the intended table","Inspect the key echoed in the message for typos/casing mismatches"],"exampleFix":"// before\nv, err := store.Get(ctx, k)\nif err != nil { log.Fatal(err) }\n// after\nv, err := store.Get(ctx, k)\nif errors.Is(err, dynamodb.ErrKeyNotFound) { v, err = loadDefault(k), nil }","handlingStrategy":"type-guard","validationCode":"// check key before calling Get\nif key == \"\" { return errors.New(\"empty key\") }\n// ensure writers use Set so items carry the 'value' attribute","typeGuard":"func IsKeyNotFound(err error) bool { return errors.Is(err, dynamodb.ErrKeyNotFound) }","tryCatchPattern":"v, err := store.Get(ctx, key)\nif errors.Is(err, dynamodb.ErrKeyNotFound) {\n    log.Printf(\"miss: %s\", key) // message contains key\n    return handleMiss(key)\n}\nif err != nil { return err }","preventionTips":["Use errors.Is, never string matching, on the wrapped sentinel","Ensure all table writers use this client's Set (uniform 'value' attribute)","Validate key format with a regex/helper before Get","Confirm table selection in configuration tests"],"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"}