Skip to content
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

Added error handling of AWS SDK errors when using groups command #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
10 changes: 7 additions & 3 deletions blade/blade.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package blade
import (
"encoding/json"
"fmt"
"github.com/aws/aws-sdk-go/aws/awserr"
"os"
"strings"
"time"
Expand Down Expand Up @@ -57,10 +58,10 @@ func NewBlade(
}

// GetLogGroups gets the log groups from AWS given the blade configuration
func (b *Blade) GetLogGroups() []*cloudwatchlogs.LogGroup {
func (b *Blade) GetLogGroups() ([]*cloudwatchlogs.LogGroup, awserr.Error) {
input := b.config.DescribeLogGroupsInput()
groups := make([]*cloudwatchlogs.LogGroup, 0)
b.cwl.DescribeLogGroupsPages(input, func(
err := b.cwl.DescribeLogGroupsPages(input, func(
out *cloudwatchlogs.DescribeLogGroupsOutput,
lastPage bool,
) bool {
Expand All @@ -69,7 +70,10 @@ func (b *Blade) GetLogGroups() []*cloudwatchlogs.LogGroup {
}
return !lastPage
})
return groups
if awsErr, ok := err.(awserr.Error); ok {
return groups, awsErr
}
return groups, nil
}

// GetLogStreams gets the log streams from AWS given the blade configuration
Expand Down
10 changes: 8 additions & 2 deletions cmd/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package cmd

import (
"fmt"

"github.com/TylerBrock/saw/blade"
"github.com/TylerBrock/saw/config"
"github.com/spf13/cobra"
"os"
)

// TODO: colorize based on logGroup prefix (/aws/lambda, /aws/kinesisfirehose, etc...)
Expand All @@ -17,7 +17,13 @@ var groupsCommand = &cobra.Command{
Long: "",
Run: func(cmd *cobra.Command, args []string) {
b := blade.NewBlade(&groupsConfig, &awsConfig, nil)
logGroups := b.GetLogGroups()
logGroups, err := b.GetLogGroups()

if err != nil {
fmt.Fprintln(os.Stderr, err.Code()+": "+err.Message())
os.Exit(1)
}

for _, group := range logGroups {
fmt.Println(*group.LogGroupName)
}
Expand Down