mirror of
https://github.com/ncruces/go-sqlite3.git
synced 2026-01-12 05:59:14 +00:00
Use finalizers to detect unclosed connections.
This commit is contained in:
9
error.go
9
error.go
@@ -1,6 +1,7 @@
|
||||
package sqlite3
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -215,3 +216,11 @@ func assertErr() errorString {
|
||||
}
|
||||
return errorString(msg)
|
||||
}
|
||||
|
||||
func finalizer[T any](skip int) func(*T) {
|
||||
msg := fmt.Sprintf("sqlite3: %T not closed", new(T))
|
||||
if _, file, line, ok := runtime.Caller(skip + 1); ok && skip >= 0 {
|
||||
msg += " (" + file + ":" + strconv.Itoa(line) + ")"
|
||||
}
|
||||
return func(*T) { panic(errorString(msg)) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user