Skip to content

Commit

Permalink
fix: use len check instead of nil check on dynamodb event record images
Browse files Browse the repository at this point in the history
  • Loading branch information
nickshine committed Jan 1, 2021
1 parent 3700514 commit eab6318
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions cmd/publisher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ func handler(ctx context.Context, e events.DynamoDBEvent) error {

var image map[string]events.DynamoDBAttributeValue

if record.Change.NewImage != nil {
if len(record.Change.NewImage) > 0 {
image = record.Change.NewImage
} else if record.Change.OldImage != nil {
} else if len(record.Change.OldImage) > 0 {
image = record.Change.OldImage
} else {
return fmt.Errorf("Invalid DynamoDBEvent: %v", e)
Expand Down Expand Up @@ -135,6 +135,7 @@ func handleDiscord(params map[string]string, messages []string) error {
}

errors := discordSession.Send(messages)
log.Debug("Discord notification sent")
for _, e := range errors {
switch v := e.(type) {
case *discord.ChannelMessageSendError:
Expand Down Expand Up @@ -167,7 +168,7 @@ func handleTweets(params map[string]string, messages []string) error {
log.Infof("Tweeting: %s\n", t)
createdAt, err := client.Tweet(t + "\n#spacex #starship")
if err != nil {
return err
log.Error(err)
}
log.Debugf("Tweet created at %s", createdAt)

Expand Down

0 comments on commit eab6318

Please sign in to comment.