From 248337b08cd016c0975cf3a0a22d4c044a2430c2 Mon Sep 17 00:00:00 2001 From: Eric Chiang Date: Fri, 8 Jan 2016 11:37:31 -0800 Subject: [PATCH] pkg: improve base64 flag error message Closes #258 --- pkg/flag/base64.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/flag/base64.go b/pkg/flag/base64.go index f60267cdb5..f232cfbba6 100644 --- a/pkg/flag/base64.go +++ b/pkg/flag/base64.go @@ -31,7 +31,7 @@ func (f *Base64) Set(s string) error { } if len(b) != f.len { - return fmt.Errorf("expected %d-byte secret", f.len) + return fmt.Errorf("expected %d-byte secret, got %d-byte secret", f.len, len(b)) } f.val = b @@ -62,11 +62,15 @@ func (f *Base64List) Set(ss string) error { if ss == "" { return nil } - for i, s := range strings.Split(ss, ",") { + splits := strings.Split(ss, ",") + for i, s := range splits { b64 := NewBase64(f.len) err := b64.Set(s) if err != nil { - return fmt.Errorf("error decoding string %d: %q", i, err) + if len(splits) == 1 { + return err + } + return fmt.Errorf("error decoding string %d: %v", i, err) } f.val = append(f.val, b64.Bytes()) }