1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-09 15:55:23 +02:00

attempt to capture errors and init the db in a way that's compatible with the rest of our codebase

This commit is contained in:
Matt Hook 2023-05-12 17:32:40 +12:00 committed by Prabhat Khera
parent 4205d871de
commit 1f38623b60
3 changed files with 21 additions and 7 deletions

View file

@ -4,9 +4,10 @@ import (
"errors"
"time"
"github.com/mattn/go-sqlite3"
portainer "github.com/portainer/portainer/api"
"github.com/portainer/portainer/api/database/models"
dserrors "github.com/portainer/portainer/api/dataservices/errors"
"gorm.io/gorm"
)
type (
@ -293,5 +294,11 @@ type (
)
func IsErrObjectNotFound(e error) bool {
return errors.Is(e, dserrors.ErrObjectNotFound)
var sqliteErr sqlite3.Error
errNotFound := false
if errors.As(e, &sqliteErr) {
errNotFound = sqliteErr.Code == sqlite3.ErrError
}
return errNotFound || errors.Is(e, gorm.ErrRecordNotFound)
}

View file

@ -7,6 +7,7 @@ import (
"path"
"time"
"github.com/mattn/go-sqlite3"
portainer "github.com/portainer/portainer/api"
portainerErrors "github.com/portainer/portainer/api/dataservices/errors"
"gorm.io/gorm"
@ -44,7 +45,7 @@ func (store *Store) Open() (newStore bool, err error) {
// TODO: check if settings exists, if not, init or leave it as is
// Init auto migrates tables if needed
store.connection.Init()
//store.connection.Init()
err = store.initServices()
if err != nil {
@ -90,7 +91,13 @@ func (store *Store) IsErrNoSuchTable(e error) bool {
// TODO: move the use of this to dataservices.IsErrObjectNotFound()?
func (store *Store) IsErrObjectNotFound(e error) bool {
return errors.Is(e, gorm.ErrRecordNotFound)
var sqliteErr sqlite3.Error
errNotFound := false
if errors.As(e, &sqliteErr) {
errNotFound = sqliteErr.Code == sqlite3.ErrError
}
return errNotFound || errors.Is(e, gorm.ErrRecordNotFound)
}
func (store *Store) Connection() portainer.Connection {

View file

@ -125,9 +125,9 @@ func (store *Store) initServices() error {
store.EndpointGroupService = endpointgroupService
endpointService, err := endpoint.NewService(store.connection)
if err != nil {
return err
}
// if err != nil {
// return err
// }
store.EndpointService = endpointService
extensionService, err := extension.NewService(store.connection)