t/cmd: make credential helper produce useful errors

The credential helper can fail in some cases when it gets data that
doesn't contain a colon.  In such a case, make it print a useful error
instead of panicking.
This commit is contained in:
brian m. carlson 2019-08-26 18:21:02 +00:00
parent 56fc55a33f
commit 1b2e4c3d4e
No known key found for this signature in database
GPG Key ID: 2D0C9BC12F82B3A1

@ -118,6 +118,9 @@ func credsFromFilename(file string) (string, string, error) {
return "", "", fmt.Errorf("Error opening %q: %s", file, err)
}
credsPieces := strings.SplitN(strings.TrimSpace(string(userPass)), ":", 2)
if len(credsPieces) != 2 {
return "", "", fmt.Errorf("Invalid data %q while reading %q", string(userPass), file)
}
return credsPieces[0], credsPieces[1], nil
}