sq/drivers/sqlite3/errors.go
Neil O'Toole 2f2dfd6e47
#229: More diff (#233)
- Implement `sq diff --data`.
2023-05-22 09:08:14 -06:00

25 lines
615 B
Go

package sqlite3
import (
"strings"
"github.com/neilotoole/sq/libsq/core/errz"
)
// 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.
return errz.NotExist(err)
default:
return errz.Err(err)
}
}