You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+3-6Lines changed: 3 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -116,10 +116,7 @@ func main() {
116
116
break
117
117
}
118
118
if err, ok := v.(error); ok {
119
-
if err, ok := err.(gojq.HaltError); ok {
120
-
if err.Value() != nil {
121
-
log.Fatalln(err)
122
-
}
119
+
if err, ok := err.(*gojq.HaltError); ok && err.Value() == nil {
123
120
break
124
121
}
125
122
log.Fatalln(err)
@@ -137,8 +134,8 @@ func main() {
137
134
- In either case, you cannot use custom type values as the query input. The type should be `[]any` for an array and `map[string]any` for a map (just like decoded to an `any` using the [encoding/json](https://golang.org/pkg/encoding/json/) package). You can't use `[]int` or `map[string]string`, for example. If you want to query your custom struct, marshal to JSON, unmarshal to `any` and use it as the query input.
138
135
- Thirdly, iterate through the results using [`iter.Next() (any, bool)`](https://pkg.go.dev/github.com/itchyny/gojq#Iter). The iterator can emit an error so make sure to handle it. The method returns `true` with results, and `false` when the iterator terminates.
139
136
- The returntype is not `(any, error)` because the iterator may emit multiple errors. The `jq` and `gojq` commands stop the iteration on the first error, but the library user can choose to stop the iteration on errors, or to continueuntil it terminates.
140
-
- In any case, it is recommended to stop the iteration on [`HaltError`](https://pkg.go.dev/github.com/itchyny/gojq#HaltError), which is emitted on`halt` and `halt_error` functions, although these functions are not commonly used.
141
-
If the error value of `HaltError` is `nil`, stop the iteration without handling the error.
137
+
- In any case, it is recommended to stop the iteration on [`gojq.HaltError`](https://pkg.go.dev/github.com/itchyny/gojq#HaltError), which is emitted by`halt` and `halt_error` functions, although these functions are rarely used.
138
+
The error implements [`gojq.ValueError`](https://pkg.go.dev/github.com/itchyny/gojq#ValueError), and if the error value is `nil`, stop the iteration without handling the error.
142
139
Technically speaking, we can fix the iterator to terminate on the halting error, but it does not terminate at the moment.
143
140
The `halt`functionin jq not only stops the iteration, but also terminates the command execution, even if there are still input values.
144
141
So, gojq leaves it up to the library user how to handle the halting error.
0 commit comments