Closed romshark closed 1 year ago
A different way to approach this, that would cover more use cases, would be to make all the iterator callbacks return an error (now some return a "error" boolean, some don't have a return value) . If error then the scan would stop. And you could have some specific errors (Found or Stop) that would just indicate that the user found the value they were looking for and wanted to stop.
@raff if I'm correct you propose allowing callbacks to return more sophisticated error values. The callback function was supposed to manage any external error reporting on its own:
depthLimitExceeded := false
err := jscan.Scan(jscan.Options{
CachePath: true,
EscapePath: true,
}, j, func(i *jscan.Iterator) (err bool) {
if i.Level > MyDepthLimit {
depthLimitExceeded = true
return true
}
return false
})
if err.IsErr() {
// There was a syntax error
}
if depthLimitExceeded {
// There was a user-defined error
}
Sometimes it's necessary to read multiple JSON values from a stream, but the following program will produce:
ERR: error at index 7 ('{'): unexpected token
Therefore I propose to extend the API by adding a new function: