Improve database errors

This commit is contained in:
Ettore Di Giacinto
2020-04-30 20:44:34 +02:00
parent 322ac99f17
commit 9cb290b484
2 changed files with 9 additions and 7 deletions

View File

@@ -17,6 +17,7 @@ package pkg
import ( import (
"encoding/base64" "encoding/base64"
"fmt"
"os" "os"
"regexp" "regexp"
"strconv" "strconv"
@@ -228,7 +229,7 @@ func (db *BoltDatabase) getProvide(p Package) (Package, error) {
db.Unlock() db.Unlock()
if !ok { if !ok {
return nil, errors.New("No versions found for package") return nil, errors.New(fmt.Sprintf("No versions found for: %s", p.HumanReadableString()))
} }
for ve, _ := range versions { for ve, _ := range versions {
@@ -240,7 +241,7 @@ func (db *BoltDatabase) getProvide(p Package) (Package, error) {
if match { if match {
pa, ok := db.ProvidesDatabase[p.GetPackageName()][ve] pa, ok := db.ProvidesDatabase[p.GetPackageName()][ve]
if !ok { if !ok {
return nil, errors.New("No versions found for package") return nil, errors.New(fmt.Sprintf("No versions found for: %s", p.HumanReadableString()))
} }
return pa, nil //pick the first (we shouldn't have providers that are conflicting) return pa, nil //pick the first (we shouldn't have providers that are conflicting)
// TODO: A find dbcall here would recurse, but would give chance to have providers of providers // TODO: A find dbcall here would recurse, but would give chance to have providers of providers
@@ -309,7 +310,7 @@ func (db *BoltDatabase) RemovePackage(p Package) error {
var found DefaultPackage var found DefaultPackage
err = bolt.Select(q.Eq("Name", p.GetName()), q.Eq("Category", p.GetCategory()), q.Eq("Version", p.GetVersion())).Limit(1).Delete(&found) err = bolt.Select(q.Eq("Name", p.GetName()), q.Eq("Category", p.GetCategory()), q.Eq("Version", p.GetVersion())).Limit(1).Delete(&found)
if err != nil { if err != nil {
return errors.Wrap(err, "No package found to delete") return errors.New(fmt.Sprintf("Package not found: %s", p.HumanReadableString()))
} }
return nil return nil
} }

View File

@@ -18,6 +18,7 @@ package pkg
import ( import (
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
"fmt"
"regexp" "regexp"
"sync" "sync"
@@ -59,7 +60,7 @@ func (db *InMemoryDatabase) Get(s string) (string, error) {
defer db.Unlock() defer db.Unlock()
pa, ok := db.Database[s] pa, ok := db.Database[s]
if !ok { if !ok {
return "", errors.New("No key found with that id") return "", errors.New(fmt.Sprintf("No key found for: %s", s))
} }
return pa, nil return pa, nil
} }
@@ -248,7 +249,7 @@ func (db *InMemoryDatabase) FindPackages(p Package) (Packages, error) {
} }
versions, ok := db.CacheNoVersion[p.GetPackageName()] versions, ok := db.CacheNoVersion[p.GetPackageName()]
if !ok { if !ok {
return nil, errors.New("No versions found for package") return nil, errors.New(fmt.Sprintf("No versions found for: %s", p.HumanReadableString()))
} }
var versionsInWorld []Package var versionsInWorld []Package
for ve, _ := range versions { for ve, _ := range versions {
@@ -277,7 +278,7 @@ func (db *InMemoryDatabase) UpdatePackage(p Package) error {
return db.Set(p.GetFingerPrint(), enc) return db.Set(p.GetFingerPrint(), enc)
return errors.New("Package not found") return errors.New(fmt.Sprintf("Package not found: %s", p.HumanReadableString()))
} }
func (db *InMemoryDatabase) GetPackages() []string { func (db *InMemoryDatabase) GetPackages() []string {
@@ -302,7 +303,7 @@ func (db *InMemoryDatabase) GetPackageFiles(p Package) ([]string, error) {
pa, ok := db.FileDatabase[p.GetFingerPrint()] pa, ok := db.FileDatabase[p.GetFingerPrint()]
if !ok { if !ok {
return pa, errors.New("No key found with that id") return pa, errors.New(fmt.Sprintf("No key found for: %s", p.HumanReadableString()))
} }
return pa, nil return pa, nil