Unwrap aggregates of size 1 when writing errors

Also, only use aggregate in get when we actually are dealing with
multiple errors.
This commit is contained in:
Clayton Coleman
2016-09-10 18:37:27 -04:00
parent 19a2a10354
commit 9bfa63dbba
3 changed files with 37 additions and 17 deletions

View File

@@ -122,6 +122,11 @@ func checkErrWithPrefix(prefix string, err error) {
// checkErr formats a given error as a string and calls the passed handleErr
// func with that string and an kubectl exit code.
func checkErr(prefix string, err error, handleErr func(string, int)) {
// unwrap aggregates of 1
if agg, ok := err.(utilerrors.Aggregate); ok && len(agg.Errors()) == 1 {
err = agg.Errors()[0]
}
switch {
case err == nil:
return