Skip to content

205 fix mini panic #226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 29, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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