goadb/util.go

41 lines
765 B
Go
Raw Normal View History

package goadb
import (
2015-07-12 06:18:58 +00:00
"fmt"
"reflect"
"regexp"
2015-07-12 06:18:58 +00:00
"strings"
"github.com/zach-klippenstein/goadb/util"
)
var (
whitespaceRegex = regexp.MustCompile(`^\s*$`)
)
func containsWhitespace(str string) bool {
return strings.ContainsAny(str, " \t\v")
}
func isBlank(str string) bool {
return whitespaceRegex.MatchString(str)
}
2015-07-12 06:18:58 +00:00
func wrapClientError(err error, client interface{}, operation string, args ...interface{}) error {
if err == nil {
return nil
}
if _, ok := err.(*util.Err); !ok {
panic("err is not a *util.Err")
}
clientType := reflect.TypeOf(client)
return &util.Err{
Code: err.(*util.Err).Code,
Cause: err,
Message: fmt.Sprintf("error performing %s on %s", fmt.Sprintf(operation, args...), clientType),
Details: client,
}
}