chbatchclose: add support for defer on no-arg closure - #8
Conversation
| }() | ||
| } | ||
|
|
||
| // invalid: deferred closure calls only Abort() (or other methods), not Close(). |
There was a problem hiding this comment.
Q: I understand that Close() is not called in this pattern. But this case looks like more restrictive. For example how do you know if Close() is not called in later defers? Plus when to call Abort() looks like out of scope for these linters? no? May be I'm missing something?
There was a problem hiding this comment.
this test is similar to this one line 23:
// invalid: defer Abort() after PrepareBatch
// defer Abort() can return an error that is ignored by defer. batch.Close should be used
func invalidDeferAbort() {
batch, err := conn.PrepareBatch(ctx, "INSERT INTO t") //want `clickhouse Batch batch must be closed defensively with defer batch\.Close\(\) after successful instantiation`
if err != nil {
return
}
defer batch.Abort()
_ = batch.Append(1)
_ = batch.Send()
}
the intent of these tests is more to be used as a specification than as actual tests. the intent is to clarify that abort is not equivalent to Close.
For example how do you know if Close() is not called in later defers?
the linter is not particularly looking at Abort, it's just observing that there is no batch.Close(), neither in the defer, neither in the rest of the function
does this answer your question?
WHAT
fix #7
batch closed in a closure was not supported
resulting in false positives
this was a known limitation, see updated tests
out of scope:
defer closeUtil(batch)withcloseUtilan util defined elsewhere - this is a legit pattern but will be implemented later, it's a bigger change