From df6c2586d9e40df1c49c91a45d595eecbe8f7cf9 Mon Sep 17 00:00:00 2001 From: Aram Petrosyan Date: Sat, 24 Aug 2019 15:35:25 +0100 Subject: [PATCH 1/3] fix mini panic --- events/attributevalue.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/events/attributevalue.go b/events/attributevalue.go index 0e645753..f897631e 100644 --- a/events/attributevalue.go +++ b/events/attributevalue.go @@ -18,6 +18,10 @@ type DynamoDBAttributeValue struct { dataType DynamoDBDataType } +// This struct represents DynamoDBAttributeValue which doesn't +// implement fmt.Stringer interface and safely printable +type dynamoDbAttributeValue DynamoDBAttributeValue + // Binary provides access to an attribute of type Binary. // Method panics if the attribute is not of type Binary. func (av DynamoDBAttributeValue) Binary() []byte { @@ -98,8 +102,13 @@ func (av DynamoDBAttributeValue) NumberSet() []string { // String provides access to an attribute of type String. // Method panics if the attribute is not of type String. func (av DynamoDBAttributeValue) String() string { - av.ensureType(DataTypeString) - return av.value.(string) + if av.dataType == DataTypeString { + return av.value.(string) + } + // If datatype is not string and you try to print the struct + // compiler would confuse with fmt.Stringer interface and would panic + // instead of printing the struct + return fmt.Sprintf("%v", dynamoDbAttributeValue(av)) } // StringSet provides access to an attribute of type String Set. @@ -214,6 +223,8 @@ const ( DataTypeStringSet ) +type dynamodbString string + type anyValue interface{} // UnsupportedDynamoDBTypeError is the error returned when trying to unmarshal a DynamoDB Attribute type not recognized by this library From c0d3e3f041f408f9f02abbff8f2c3cfc996000a0 Mon Sep 17 00:00:00 2001 From: Aram Petrosyan Date: Sat, 24 Aug 2019 15:46:04 +0100 Subject: [PATCH 2/3] fix mini panic --- events/attributevalue.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/events/attributevalue.go b/events/attributevalue.go index f897631e..bbdffd10 100644 --- a/events/attributevalue.go +++ b/events/attributevalue.go @@ -19,7 +19,7 @@ type DynamoDBAttributeValue struct { } // This struct represents DynamoDBAttributeValue which doesn't -// implement fmt.Stringer interface and safely printable +// implement fmt.Stringer interface and safely `fmt.Sprintf`able type dynamoDbAttributeValue DynamoDBAttributeValue // Binary provides access to an attribute of type Binary. @@ -105,9 +105,9 @@ func (av DynamoDBAttributeValue) String() string { if av.dataType == DataTypeString { return av.value.(string) } - // If datatype is not string and you try to print the struct - // compiler would confuse with fmt.Stringer interface and would panic - // instead of printing the struct + // If dataType is not DataTypeString during fmt.Sprintf("%#v", ...) + // compiler confuses with fmt.Stringer interface and panics + // instead of printing the struct. return fmt.Sprintf("%v", dynamoDbAttributeValue(av)) } From 7d86c2f66217096b0d48788f5a7d89622da3f57a Mon Sep 17 00:00:00 2001 From: Aram Petrosyan Date: Sat, 24 Aug 2019 15:46:22 +0100 Subject: [PATCH 3/3] fix mini panic --- events/attributevalue.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/events/attributevalue.go b/events/attributevalue.go index bbdffd10..72de66ab 100644 --- a/events/attributevalue.go +++ b/events/attributevalue.go @@ -223,8 +223,6 @@ const ( DataTypeStringSet ) -type dynamodbString string - type anyValue interface{} // UnsupportedDynamoDBTypeError is the error returned when trying to unmarshal a DynamoDB Attribute type not recognized by this library