pkg: improve base64 flag error message

Closes #258
This commit is contained in:
Eric Chiang 2016-01-08 11:37:31 -08:00
parent d5bdb2e731
commit 248337b08c

View file

@ -31,7 +31,7 @@ func (f *Base64) Set(s string) error {
} }
if len(b) != f.len { 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 f.val = b
@ -62,11 +62,15 @@ func (f *Base64List) Set(ss string) error {
if ss == "" { if ss == "" {
return nil return nil
} }
for i, s := range strings.Split(ss, ",") { splits := strings.Split(ss, ",")
for i, s := range splits {
b64 := NewBase64(f.len) b64 := NewBase64(f.len)
err := b64.Set(s) err := b64.Set(s)
if err != nil { 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()) f.val = append(f.val, b64.Bytes())
} }