Skip to content

Commit 6dcebde

Browse files
skmcgrailjasdel
authored andcommitted
service/dynamodb/expression: Improved reporting of bad key conditions (#360)
Improves the reporting of errors when an invalid key condition is constructed using the DynamoDB expression package. Related to aws/aws-sdk-go#2775
1 parent 8209df6 commit 6dcebde

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

CHANGELOG_PENDING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@
1717
* `aws/ec2rolecreds`: Fix security creds path to include trailing slash ([#356](https://github.com/aws/aws-sdk-go-v2/pull/356))
1818
* Fixes the iamSecurityCredsPath var to include a trailing slash preventing redirects when making requests to the EC2 Instance Metadata service.
1919
* Fixes [#351](https://github.com/aws/aws-sdk-go-v2/issues/351)
20+
* `service/dynamodb/expression`: Improved reporting of bad key conditions ([#360](https://github.com/aws/aws-sdk-go-v2/pull/360))
21+
* Improved error reporting when invalid key conditions are constructed using KeyConditionBuilder
2022

service/dynamodb/expression/key_condition.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ type keyConditionMode int
1111
const (
1212
// unsetKeyCond catches errors for unset KeyConditionBuilder structs
1313
unsetKeyCond keyConditionMode = iota
14+
// invalidKeyCond catches errors in the construction of KeyConditionBuilder structs
15+
invalidKeyCond
1416
// equalKeyCond represents the Equals KeyCondition
1517
equalKeyCond
1618
// lessThanKeyCond represents the Less Than KeyCondition
@@ -305,12 +307,12 @@ func (kb KeyBuilder) GreaterThanEqual(valueBuilder ValueBuilder) KeyConditionBui
305307
func KeyAnd(left, right KeyConditionBuilder) KeyConditionBuilder {
306308
if left.mode != equalKeyCond {
307309
return KeyConditionBuilder{
308-
mode: andKeyCond,
310+
mode: invalidKeyCond,
309311
}
310312
}
311313
if right.mode == andKeyCond {
312314
return KeyConditionBuilder{
313-
mode: andKeyCond,
315+
mode: invalidKeyCond,
314316
}
315317
}
316318
return KeyConditionBuilder{
@@ -468,6 +470,8 @@ func (kcb KeyConditionBuilder) buildTree() (exprNode, error) {
468470
return beginsWithBuildKeyCondition(ret)
469471
case unsetKeyCond:
470472
return exprNode{}, newUnsetParameterError("buildTree", "KeyConditionBuilder")
473+
case invalidKeyCond:
474+
return exprNode{}, fmt.Errorf("buildKeyCondition error: invalid key condition constructed")
471475
default:
472476
return exprNode{}, fmt.Errorf("buildKeyCondition error: unsupported mode: %v", kcb.mode)
473477
}

service/dynamodb/expression/key_condition_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ const (
2222
// invalidKeyConditionOperand error will occur when an invalid OperandBuilder is used as
2323
// an argument
2424
invalidKeyConditionOperand = "BuildOperand error"
25-
// invalidAndFormat error will occur when the first key condition is not an equal
26-
// clause or if the second key condition is an and condition.
27-
invalidAndFormat = "invalid parameter: KeyConditionBuilder"
25+
// invalidKeyConditionFormat error will occur when the first key condition is not an equal
26+
// clause or if more then one And condition is provided
27+
invalidKeyConditionFormat = "buildKeyCondition error: invalid key condition constructed"
2828
)
2929

3030
func TestKeyCompare(t *testing.T) {
@@ -336,12 +336,12 @@ func TestKeyAnd(t *testing.T) {
336336
{
337337
name: "first condition is not equal",
338338
input: Key("foo").LessThan(Value(5)).And(Key("bar").BeginsWith("baz")),
339-
err: invalidAndFormat,
339+
err: invalidKeyConditionFormat,
340340
},
341341
{
342-
name: "second condition is and",
342+
name: "more then one condition on key",
343343
input: Key("foo").Equal(Value(5)).And(Key("bar").Equal(Value(1)).And(Key("baz").BeginsWith("yar"))),
344-
err: invalidAndFormat,
344+
err: invalidKeyConditionFormat,
345345
},
346346
{
347347
name: "operand error",

0 commit comments

Comments
 (0)