Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
Merge pull request #7 from tomwilkie/6-logging
Browse files Browse the repository at this point in the history
Make kv.NewNotFoundError format a string.
  • Loading branch information
munnerz authored Nov 30, 2017
2 parents 69b055c + b6db265 commit 69f5477
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
3 changes: 1 addition & 2 deletions pkg/kv/aws_kms/aws_kms_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package aws_kms

import (
"fmt"
"os"
"testing"

Expand Down Expand Up @@ -30,7 +29,7 @@ func (f *fakeKV) Set(key string, data []byte) error {
func (f *fakeKV) Get(key string) ([]byte, error) {
out, ok := f.Values[key]
if !ok {
return []byte{}, kv.NewNotFoundError(fmt.Sprintf("key '%s' not found", key))
return []byte{}, kv.NewNotFoundError("key '%s' not found", key)
}
return *out, nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/aws_ssm/aws_ssm.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (a *awsSSM) Get(key string) ([]byte, error) {
}

if len(out.Parameters) < 1 {
return []byte{}, kv.NewNotFoundError("key '%s' not found")
return []byte{}, kv.NewNotFoundError("key '%s' not found", key)
}

return base64.StdEncoding.DecodeString(*out.Parameters[0].Value)
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/gcs/gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (g *gcsStorage) Get(key string) ([]byte, error) {

if err != nil {
if err == storage.ErrObjectNotExist {
return nil, kv.NewNotFoundError(fmt.Sprintf("error getting object for key '%s': %s", n, err.Error()))
return nil, kv.NewNotFoundError("error getting object for key '%s': %s", n, err.Error())
}
return nil, fmt.Errorf("error getting object for key '%s': %s", n, err.Error())
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/kv/storage.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package kv

import "fmt"

type NotFoundError struct {
msg string // description of error
}

func (e *NotFoundError) Error() string { return e.msg }

func NewNotFoundError(msg string) *NotFoundError {
func NewNotFoundError(msg string, args ...interface{}) *NotFoundError {
return &NotFoundError{
msg: msg,
msg: fmt.Sprintf(msg, args...),
}
}

Expand Down

0 comments on commit 69f5477

Please sign in to comment.