Skip to content

Commit fe4f484

Browse files
apzuk3bmoffatt
authored andcommitted
205 fix mini panic (#226)
* fix mini panic * fix mini panic * fix mini panic
1 parent ec56cb7 commit fe4f484

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

events/attributevalue.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ type DynamoDBAttributeValue struct {
1818
dataType DynamoDBDataType
1919
}
2020

21+
// This struct represents DynamoDBAttributeValue which doesn't
22+
// implement fmt.Stringer interface and safely `fmt.Sprintf`able
23+
type dynamoDbAttributeValue DynamoDBAttributeValue
24+
2125
// Binary provides access to an attribute of type Binary.
2226
// Method panics if the attribute is not of type Binary.
2327
func (av DynamoDBAttributeValue) Binary() []byte {
@@ -98,8 +102,13 @@ func (av DynamoDBAttributeValue) NumberSet() []string {
98102
// String provides access to an attribute of type String.
99103
// Method panics if the attribute is not of type String.
100104
func (av DynamoDBAttributeValue) String() string {
101-
av.ensureType(DataTypeString)
102-
return av.value.(string)
105+
if av.dataType == DataTypeString {
106+
return av.value.(string)
107+
}
108+
// If dataType is not DataTypeString during fmt.Sprintf("%#v", ...)
109+
// compiler confuses with fmt.Stringer interface and panics
110+
// instead of printing the struct.
111+
return fmt.Sprintf("%v", dynamoDbAttributeValue(av))
103112
}
104113

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

0 commit comments

Comments
 (0)