I am trying to convert an err in Go to go-sqlite3.Error, but it fails always. Above image represents the snapshot of my debug windows, which shows that the err is of type go-sqlite3.Error
I am using below code to type cast.
import (
"github.com/mattn/go-sqlite3"
)
if err != nil {
if sqlite3Err, ok := err.(*sqlite3.Error); ok {
if sqlite3Err.Code == sqlite3.ErrConstraint && sqlite3Err.ExtendedCode == 1555 {
// SQLITE3 ERROR 1555 : PRIMARY KEY CONSTRAINT ERROR
return errors.New("Log Error")
}
}
try the following example. err.(*sqlite3.Error)
is changed to err.(sqlite3.Error)
if sqlite3Err, ok := err.(sqlite3.Error); ok {
if sqlite3Err.Code == sqlite3.ErrConstraint &&
sqlite3Err.ExtendedCode == 1555 {
// logic
}
}