2023-05-22 18:08:14 +03:00
|
|
|
package sqlite3
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/neilotoole/sq/libsq/core/errz"
|
2024-01-15 04:45:34 +03:00
|
|
|
"github.com/neilotoole/sq/libsq/driver"
|
2023-05-22 18:08:14 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// errw wraps any error from the db. It should be called at
|
|
|
|
// every interaction with the db. If err is nil, nil is returned.
|
|
|
|
// Certain errors will be wrapped in specific error types,
|
|
|
|
// e.g, errz.NotExistError.
|
|
|
|
func errw(err error) error {
|
|
|
|
switch {
|
|
|
|
case err == nil:
|
|
|
|
return nil
|
|
|
|
case strings.HasPrefix(err.Error(), "no such table:"):
|
|
|
|
// The sqlite driver always returns sqlite3.ErrError(1), so
|
|
|
|
// we need to search by string. Needs further investigation.
|
2024-01-15 04:45:34 +03:00
|
|
|
return driver.NewNotExistError(err)
|
2023-05-22 18:08:14 +03:00
|
|
|
default:
|
|
|
|
return errz.Err(err)
|
|
|
|
}
|
|
|
|
}
|