Cannot get Error from callback
yb3616 opened this issue · 4 comments
+1, for now error passed to callback will be always nil and break will never occur. I think the right api would be:
func ArrayEach(data []byte, cb func(value []byte, dataType ValueType, offset int) error, keys ...string) (offset int, err error)
@PiotrKozimor you are right that callback at the moment never receive the error. But I guess proper way to handle it will be smth like:
Instead of
Lines 1028 to 1030 in 09bcf22
Do
if err != nil {
cb(nil, t, offset+o-len(v), e)
return offset, e
}
Well it does not make TOO much sense from API point of view, since it always returns on the first error. But at least it does not break API (I really care about backward compatibility).
I've set v2 milestone, so when we do next major release, we can "remove" err object from callback or fix it in another way.
@buger It would make sense as a temporary, compatible fix.
Going back to my breaking suggestion - when error is returned from callback, iterating over array would be stopped and this error would be returned from ArrayEach
. That's how I see it. Fail fast could bring benefit in some use cases.
Agree with @PiotrKozimor recommendation, I would like that behavior and that would bring it inline with ObjectEach, I think.