2016-01-15 15:54:27 +00:00
|
|
|
package adb
|
2015-04-12 20:34:20 +00:00
|
|
|
|
|
|
|
import (
|
2015-07-12 06:18:58 +00:00
|
|
|
"fmt"
|
|
|
|
"reflect"
|
2015-04-12 20:34:20 +00:00
|
|
|
"regexp"
|
2015-07-12 06:18:58 +00:00
|
|
|
"strings"
|
|
|
|
|
2016-05-22 17:49:32 +00:00
|
|
|
"github.com/zach-klippenstein/goadb/internal/errors"
|
2015-04-12 20:34:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2016-05-22 17:49:32 +00:00
|
|
|
if _, ok := err.(*errors.Err); !ok {
|
|
|
|
panic("err is not a *Err: " + err.Error())
|
2015-07-12 06:18:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
clientType := reflect.TypeOf(client)
|
|
|
|
|
2016-05-22 17:49:32 +00:00
|
|
|
return &errors.Err{
|
|
|
|
Code: err.(*errors.Err).Code,
|
2015-07-12 06:18:58 +00:00
|
|
|
Cause: err,
|
|
|
|
Message: fmt.Sprintf("error performing %s on %s", fmt.Sprintf(operation, args...), clientType),
|
|
|
|
Details: client,
|
|
|
|
}
|
|
|
|
}
|