Merge pull request #259 from ericchiang/secret_errors

pkg: improve base64 flag error message
This commit is contained in:
bobbyrullo 2016-01-08 16:39:43 -08:00
commit 217e26691c

View file

@ -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())
}