Repository navigation
replace interface{} with any in db.go according to modern 1.18+ go standards - #2677
Conversation
There was a problem hiding this comment.
Code Review
This pull request replaces the interface{} type with any in the qualifyRowColumns function within db/db.go. A review comment suggests implementing a check for the type assertion of the driver connection to ensure safety and prevent potential runtime panics.
| err := conn.Raw(func(driverConn any) error { | ||
| sqliteConn := driverConn.(*sqlite3.SQLiteConn) |
There was a problem hiding this comment.
The type assertion driverConn.(*sqlite3.SQLiteConn) is performed without checking the success of the assertion. While rqlite currently uses the go-sqlite3 driver, it is safer to use the "comma-ok" idiom to avoid a potential panic if the underlying driver connection is not of the expected type (e.g., if a wrapper or different driver is used in the future). Additionally, while replacing interface{} with any is a good modernization for Go 1.18+, it is worth noting that this is a type alias and does not provide performance benefits as implied by the PR title.
err := conn.Raw(func(driverConn any) error {
sqliteConn, ok := driverConn.(*sqlite3.SQLiteConn)
if !ok {
return fmt.Errorf("unexpected driver connection type: %T", driverConn)
}References
- Enforce defensive programming by ensuring type assertions are checked to prevent runtime panics.
|
Thanks for your contribution @DARSHANR007 |
Replaced interface with any in go available from 1.18+ in db.go