-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrconv.go
More file actions
22 lines (19 loc) · 758 Bytes
/
strconv.go
File metadata and controls
22 lines (19 loc) · 758 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package main
import (
"errors"
"strings"
)
// The errors returned by strconv and flag result in a lot of duplicate info presented to
// the user so this function trims up the strconv error. It assumes a standard strconv
// error syntax of "function: Action: error message" thus we extract the third colon
// delimited value and turn that into an error. However, given that "Action" could contain
// a colon, what we actually do is select the last colon delimited value. If the syntax is
// not as expected, return the whole error as at worst it makes for a verbose error
// message.
func strconvTrimError(err error) error {
es := strings.Split(err.Error(), ":")
if len(es) >= 3 {
return errors.New(strings.TrimSpace(es[len(es)-1]))
}
return err
}