Skip to content

Commit

Permalink
205 fix mini panic (#226)
Browse files Browse the repository at this point in the history
* fix mini panic

* fix mini panic

* fix mini panic
  • Loading branch information
apzuk3 authored and bmoffatt committed Aug 29, 2019
1 parent ec56cb7 commit fe4f484
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions events/attributevalue.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ type DynamoDBAttributeValue struct {
dataType DynamoDBDataType
}

// This struct represents DynamoDBAttributeValue which doesn't
// implement fmt.Stringer interface and safely `fmt.Sprintf`able
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 {
Expand Down Expand Up @@ -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 DataTypeString during fmt.Sprintf("%#v", ...)
// compiler confuses with fmt.Stringer interface and panics
// instead of printing the struct.
return fmt.Sprintf("%v", dynamoDbAttributeValue(av))
}

// StringSet provides access to an attribute of type String Set.
Expand Down

0 comments on commit fe4f484

Please sign in to comment.