Problem
The documented behavior for the DynamoDBAttributeValue.String() method, similar to the other accessor methods, states:
Method panics if the attribute is not of type String.
However, this does not appear to be the case.
Example
Using this code:
func IncorrectBehaviorExample() {
input := []byte(`{"MyField": {"BOOL": true}}`)
var item map[string]events.DynamoDBAttributeValue
if err := json.Unmarshal(input, &item); err != nil {
panic(err)
}
fmt.Println("Result:", item["MyField"].String())
}
does not panic, but outputs Result: {true 1}.
This is unlike the other accessor methods, such as .Number(), e.g.:
func CorrectBehaviorExample() {
input := []byte(`{"MyField": {"BOOL": true}}`)
var item map[string]events.DynamoDBAttributeValue
if err := json.Unmarshal(input, &item); err != nil {
panic(err)
}
fmt.Println("Result:", item["MyField"].Number())
}
which panics with panic: accessor called for incompatible type, requested type 5 but actual type was 1.
Suggestions
Either of:
- Preferred: The method should panic if the attribute is not of type String, which is consistent with the documented behavior as well as the behavior of the other accessor methods.
- Update the documentation so that it correctly reflects the behavior of the method.
Additional information
- Observed when using
github.com/aws/aws-lambda-go v1.41.0
- Go
1.20
Problem
The documented behavior for the
DynamoDBAttributeValue.String()method, similar to the other accessor methods, states:However, this does not appear to be the case.
Example
Using this code:
does not panic, but outputs
Result: {true 1}.This is unlike the other accessor methods, such as
.Number(), e.g.:which panics with
panic: accessor called for incompatible type, requested type 5 but actual type was 1.Suggestions
Either of:
Additional information
github.com/aws/aws-lambda-go v1.41.01.20