Skip to content

Commit

Permalink
gojq: Update gojq fq fork
Browse files Browse the repository at this point in the history
Removed some unneeded error changes in fork
  • Loading branch information
wader committed Sep 12, 2021
1 parent dfcefc1 commit f828ae1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/pmezard/go-difflib v1.0.0

// fork of github.com/itchyny/gojq
github.com/wader/gojq v0.12.1-0.20210828123808-8b2b8dc59c96
github.com/wader/gojq v0.12.1-0.20210829105258-55e2b13fae52
// fork of github.com/chzyer/readline
github.com/wader/readline v0.0.0-20210817095433-c868eb04b8b2
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ github.com/nbutton23/zxcvbn-go v0.0.0-20210217022336-fa2cb2858354/go.mod h1:KSVJ
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.1.4/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/wader/gojq v0.12.1-0.20210828123808-8b2b8dc59c96 h1:Iq45/Ijr6jqoqDpmVsEuD2iug6zmeOdgpe8ikqctFPo=
github.com/wader/gojq v0.12.1-0.20210828123808-8b2b8dc59c96/go.mod h1:AmH/OqHVd1Ce1hurSMpGpL79EXPXzEJG3zvYspUmCA8=
github.com/wader/gojq v0.12.1-0.20210829105258-55e2b13fae52 h1:nM+TA2+IDR6VcUDTA9KDcVX63dCjNJqJ1tedaUPSpZY=
github.com/wader/gojq v0.12.1-0.20210829105258-55e2b13fae52/go.mod h1:AmH/OqHVd1Ce1hurSMpGpL79EXPXzEJG3zvYspUmCA8=
github.com/wader/readline v0.0.0-20210817095433-c868eb04b8b2 h1:MGg7fsdEsoi7rattHGyU21wpOPeL3FonbUbJibpPBxc=
github.com/wader/readline v0.0.0-20210817095433-c868eb04b8b2/go.mod h1:jYXyt9wQg3DifxQ8FM5M/ZoskO23GIwmo05QLHtO9CQ=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
23 changes: 8 additions & 15 deletions pkg/interp/interp.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,22 +404,14 @@ func toValue(opts Options, v interface{}) (interface{}, bool) {
}
}

// TODO: would be nice if gojq had something for this? maybe missing something?
func queryErrorPosition(v error) pos.Pos {
func queryErrorPosition(src string, v error) pos.Pos {
var offset int
var content string

if tokIf, ok := v.(interface{ Token() (string, int) }); ok { //nolint:errorlint
_, offset = tokIf.Token()
}
if qeIf, ok := v.(interface { //nolint:errorlint
QueryParseError() (string, string, string, error)
}); ok {
_, _, content, _ = qeIf.QueryParseError()
}

if offset >= 0 {
return pos.NewFromOffset(content, offset)
return pos.NewFromOffset(src, offset)
}
return pos.Pos{}
}
Expand Down Expand Up @@ -477,7 +469,7 @@ func New(os OS, registry *registry.Registry) (*Interp, error) {
i.includeCache = map[string]*gojq.Query{}
i.initFqQuery, err = gojq.Parse(initSource)
if err != nil {
return nil, fmt.Errorf("init:%s: %w", queryErrorPosition(err), err)
return nil, fmt.Errorf("init:%s: %w", queryErrorPosition(initSource, err), err)
}
// TODO: refactor ctxstack have a CancelTop and return c context to Stop?
i.interruptStack = ctxstack.New(func(stopCh chan struct{}) {
Expand Down Expand Up @@ -548,7 +540,7 @@ func (i *Interp) Eval(ctx context.Context, mode RunMode, c interface{}, src stri

gq, err := gojq.Parse(src)
if err != nil {
p := queryErrorPosition(err)
p := queryErrorPosition(src, err)
return nil, compileError{
err: err,
what: "parse",
Expand Down Expand Up @@ -688,9 +680,10 @@ func (i *Interp) Eval(ctx context.Context, mode RunMode, c interface{}, src stri
if err != nil {
return nil, err
}
q, err := gojq.Parse(string(b))
s := string(b)
q, err := gojq.Parse(s)
if err != nil {
p := queryErrorPosition(err)
p := queryErrorPosition(s, err)
return nil, compileError{
err: err,
what: "parse",
Expand All @@ -712,7 +705,7 @@ func (i *Interp) Eval(ctx context.Context, mode RunMode, c interface{}, src stri

gc, err := gojq.Compile(gq, compilerOpts...)
if err != nil {
p := queryErrorPosition(err)
p := queryErrorPosition(src, err)
return nil, compileError{
err: err,
what: "compile",
Expand Down

0 comments on commit f828ae1

Please sign in to comment.