container: ViewDB: return typed system errors

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-07-08 13:29:56 +02:00
parent 94dea2018e
commit 6549a270e9
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
3 changed files with 9 additions and 9 deletions

View file

@ -100,7 +100,7 @@ type ViewDB struct {
func NewViewDB() (*ViewDB, error) {
store, err := memdb.NewMemDB(schema)
if err != nil {
return nil, err
return nil, errdefs.System(err)
}
return &ViewDB{store: store}, nil
}
@ -151,7 +151,7 @@ func (db *ViewDB) withTxn(cb func(*memdb.Txn) error) error {
err := cb(txn)
if err != nil {
txn.Abort()
return err
return errdefs.System(err)
}
txn.Commit()
return nil
@ -190,7 +190,7 @@ func (db *ViewDB) ReserveName(name, containerID string) error {
return db.withTxn(func(txn *memdb.Txn) error {
s, err := txn.First(memdbNamesTable, memdbIDIndex, name)
if err != nil {
return err
return errdefs.System(err)
}
if s != nil {
if s.(nameAssociation).containerID != containerID {
@ -220,7 +220,7 @@ func (v *View) All() ([]Snapshot, error) {
var all []Snapshot
iter, err := v.txn.Get(memdbContainersTable, memdbIDIndex)
if err != nil {
return nil, err
return nil, errdefs.System(err)
}
for {
item := iter.Next()
@ -237,7 +237,7 @@ func (v *View) All() ([]Snapshot, error) {
func (v *View) Get(id string) (*Snapshot, error) {
s, err := v.txn.First(memdbContainersTable, memdbIDIndex, id)
if err != nil {
return nil, err
return nil, errdefs.System(err)
}
if s == nil {
return nil, errdefs.NotFound(errors.New("No such container: " + id))
@ -268,7 +268,7 @@ func (v *View) getNames(containerID string) []string {
func (v *View) GetID(name string) (string, error) {
s, err := v.txn.First(memdbNamesTable, memdbIDIndex, name)
if err != nil {
return "", err
return "", errdefs.System(err)
}
if s == nil {
return "", ErrNameNotReserved

View file

@ -647,7 +647,7 @@ func (daemon *Daemon) parents(c *container.Container) map[string]*container.Cont
func (daemon *Daemon) registerLink(parent, child *container.Container, alias string) error {
fullName := path.Join(parent.Name, alias)
if err := daemon.containersReplica.ReserveName(fullName, child.ID); err != nil {
if err == container.ErrNameReserved {
if errors.Is(err, container.ErrNameReserved) {
logrus.Warnf("error registering link for %s, to %s, as alias %s, ignoring: %v", parent.ID, child.ID, alias, err)
return nil
}

View file

@ -64,7 +64,7 @@ func (daemon *Daemon) reserveName(id, name string) (string, error) {
}
if err := daemon.containersReplica.ReserveName(name, id); err != nil {
if err == container.ErrNameReserved {
if errors.Is(err, container.ErrNameReserved) {
id, err := daemon.containersReplica.Snapshot().GetID(name)
if err != nil {
logrus.Errorf("got unexpected error while looking up reserved name: %v", err)
@ -90,7 +90,7 @@ func (daemon *Daemon) generateNewName(id string) (string, error) {
}
if err := daemon.containersReplica.ReserveName(name, id); err != nil {
if err == container.ErrNameReserved {
if errors.Is(err, container.ErrNameReserved) {
continue
}
return "", err