Skip to content

Commit

Permalink
Merge pull request #32 from maplebed/master
Browse files Browse the repository at this point in the history
adding more descriptive errors
  • Loading branch information
dfuentes authored Oct 3, 2017
2 parents 688f832 + 3530796 commit 58d5bd4
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 16 deletions.
8 changes: 4 additions & 4 deletions cmd/exec.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package cmd

import (
"errors"
"fmt"
"os"
"os/exec"
"os/signal"
"strings"
"syscall"

"github.com/pkg/errors"
"github.com/segmentio/chamber/store"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -54,12 +54,12 @@ func execRun(cmd *cobra.Command, args []string) error {
secretStore := store.NewSSMStore()
for _, service := range args {
if err := validateService(service); err != nil {
return err
return errors.Wrap(err, "Failed to validate service")
}

secrets, err := secretStore.List(strings.ToLower(service), true)
if err != nil {
return err
return errors.Wrap(err, "Failed to list store contents")
}
for _, secret := range secrets {
envVarKey := strings.ToUpper(key(secret.Meta.Key))
Expand Down Expand Up @@ -92,7 +92,7 @@ func execRun(cmd *cobra.Command, args []string) error {
var waitStatus syscall.WaitStatus
if err := ecmd.Run(); err != nil {
if err != nil {
return err
return errors.Wrap(err, "Failed to run command")
}
if exitError, ok := err.(*exec.ExitError); ok {
waitStatus = exitError.Sys().(syscall.WaitStatus)
Expand Down
7 changes: 4 additions & 3 deletions cmd/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"
"text/tabwriter"

"github.com/pkg/errors"
"github.com/segmentio/chamber/store"
"github.com/spf13/cobra"
)
Expand All @@ -31,12 +32,12 @@ func history(cmd *cobra.Command, args []string) error {

service := strings.ToLower(args[0])
if err := validateService(service); err != nil {
return err
return errors.Wrap(err, "Failed to validate service")
}

key := strings.ToLower(args[1])
if err := validateKey(key); err != nil {
return err
return errors.Wrap(err, "Failed to validate key")
}

secretStore := store.NewSSMStore()
Expand All @@ -47,7 +48,7 @@ func history(cmd *cobra.Command, args []string) error {

events, err := secretStore.History(secretId)
if err != nil {
return err
return errors.Wrap(err, "Failed to get history")
}

w := tabwriter.NewWriter(os.Stdout, 0, 8, 2, '\t', 0)
Expand Down
5 changes: 3 additions & 2 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"
"text/tabwriter"

"github.com/pkg/errors"
"github.com/segmentio/chamber/store"
"github.com/spf13/cobra"
)
Expand All @@ -31,13 +32,13 @@ func list(cmd *cobra.Command, args []string) error {

service := strings.ToLower(args[0])
if err := validateService(service); err != nil {
return err
return errors.Wrap(err, "Failed to validate service")
}

secretStore := store.NewSSMStore()
secrets, err := secretStore.List(service, false)
if err != nil {
return err
return errors.Wrap(err, "Failed to list store contents")
}

w := tabwriter.NewWriter(os.Stdout, 0, 8, 2, '\t', 0)
Expand Down
7 changes: 4 additions & 3 deletions cmd/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"
"text/tabwriter"

"github.com/pkg/errors"
"github.com/segmentio/chamber/store"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -38,12 +39,12 @@ func read(cmd *cobra.Command, args []string) error {

service := strings.ToLower(args[0])
if err := validateService(service); err != nil {
return err
return errors.Wrap(err, "Failed to validate service")
}

key := strings.ToLower(args[1])
if err := validateKey(key); err != nil {
return err
return errors.Wrap(err, "Failed to validate key")
}

secretStore := store.NewSSMStore()
Expand All @@ -54,7 +55,7 @@ func read(cmd *cobra.Command, args []string) error {

secret, err := secretStore.Read(secretId, version)
if err != nil {
return err
return errors.Wrap(err, "Failed to read")
}

if quiet {
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var RootCmd = &cobra.Command{
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
if err := RootCmd.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
fmt.Fprintf(os.Stderr, "chamber error: %s\n", err)
switch err {
case ErrTooFewArguments, ErrTooManyArguments:
RootCmd.Usage()
Expand Down
6 changes: 3 additions & 3 deletions cmd/write.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package cmd

import (
"errors"
"strings"

"github.com/pkg/errors"
"github.com/segmentio/chamber/store"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -34,12 +34,12 @@ func write(cmd *cobra.Command, args []string) error {

service := strings.ToLower(args[0])
if err := validateService(service); err != nil {
return err
return errors.Wrap(err, "Failed to validate service")
}

key := strings.ToLower(args[1])
if err := validateKey(key); err != nil {
return err
return errors.Wrap(err, "Failed to validate key")
}

value := args[2]
Expand Down
6 changes: 6 additions & 0 deletions vendor/vendor.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@
"revision": "3bc643c63c6f8716320182b6842581d6c80572fa",
"revisionTime": "2017-03-23T00:38:48Z"
},
{
"checksumSHA1": "9guv02oL7uLkwqQNjJv8AJxWXmQ=",
"path": "github.com/pkg/errors",
"revision": "ff09b135c25aae272398c51a07235b90a75aa4f0",
"revisionTime": "2017-03-16T20:15:38Z"
},
{
"checksumSHA1": "zKKp5SZ3d3ycKe4EKMNT0BqAWBw=",
"origin": "github.com/stretchr/testify/vendor/github.com/pmezard/go-difflib/difflib",
Expand Down

0 comments on commit 58d5bd4

Please sign in to comment.