forked from golangci/golangci-lint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
39 lines (33 loc) · 750 Bytes
/
errors.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
package packages
import (
"fmt"
"go/token"
"strconv"
"strings"
"github.com/pkg/errors"
)
//nolint:gomnd,stylecheck
func ParseErrorPosition(pos string) (*token.Position, error) {
// file:line(<optional>:colon)
parts := strings.Split(pos, ":")
if len(parts) == 1 {
return nil, errors.New("no colons")
}
file := parts[0]
line, err := strconv.Atoi(parts[1])
if err != nil {
return nil, fmt.Errorf("can't parse line number %q: %s", parts[1], err)
}
var column int
if len(parts) == 3 { // no column
column, err = strconv.Atoi(parts[2])
if err != nil {
return nil, errors.Wrapf(err, "failed to parse column from %q", parts[2])
}
}
return &token.Position{
Filename: file,
Line: line,
Column: column,
}, nil
}