forked from zach-klippenstein/goadb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
40 lines (32 loc) · 791 Bytes
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package adb
import (
"fmt"
"reflect"
"regexp"
"strings"
"github.com/zach-klippenstein/goadb/internal/errors"
)
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)
}
func wrapClientError(err error, client interface{}, operation string, args ...interface{}) error {
if err == nil {
return nil
}
if _, ok := err.(*errors.Err); !ok {
panic("err is not a *Err: " + err.Error())
}
clientType := reflect.TypeOf(client)
return &errors.Err{
Code: err.(*errors.Err).Code,
Cause: err,
Message: fmt.Sprintf("error performing %s on %s", fmt.Sprintf(operation, args...), clientType),
Details: client,
}
}