cli / go-gh

A Go module for interacting with gh and the GitHub API from the command line.
https://pkg.go.dev/github.com/cli/go-gh/v2
MIT License
322 stars 45 forks source link

jq: bump up gojq, better query parse error, handle halt error gracefully #155

Closed itchyny closed 2 months ago

itchyny commented 3 months ago

The error of invalid --jq query is difficult to know what's wrong with the query. As a gojq library maintainer, I was wondering whether the library should return pretty error or not, but since the query input is given by library user, returning an error with offset is enough as a library, just like json.SyntaxError. In the release v0.12.15, I decided to export gojq.ParseError, which has the offset position in the query. This PR improves the parsing error message to report that position in fancy style. It also improves handling of halt errors.

 $ gh api /user --jq '[1,2,3,,4,5]'    
unexpected token ","

 $ bin/gh api /user --jq '[1,2,3,,4,5]'
failed to parse jq expression (line 1, column 8)
    [1,2,3,,4,5]
           ^  unexpected token ","