Skip to content

Commit

Permalink
add context for some errors which can be faced to load the packages (#…
Browse files Browse the repository at this point in the history
…953)

Signed-off-by: Camila Macedo <cmacedo@redhat.com>
  • Loading branch information
camilamacedo86 authored May 24, 2022
1 parent 23efd2c commit dd41163
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 32 deletions.
4 changes: 2 additions & 2 deletions pkg/registry/populator.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func (i *DirectoryPopulator) loadManifestsSemver(bundle *Bundle, skippatch bool)
}

if err := i.loader.AddBundleSemver(updatedGraph, bundle); err != nil {
return fmt.Errorf("error loading bundle into db: %s", err)
return fmt.Errorf("error loading bundle %s into db: %s", bundle.Name, err)
}

return nil
Expand All @@ -268,7 +268,7 @@ func (i *DirectoryPopulator) loadOperatorBundle(manifest PackageManifest, bundle
}

if err := i.loader.AddBundlePackageChannels(manifest, bundle); err != nil {
return fmt.Errorf("error loading bundle into db: %s", err)
return fmt.Errorf("error loading bundle %s into db: %s", bundle.Name, err)
}

return nil
Expand Down
42 changes: 21 additions & 21 deletions pkg/sqlite/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ func (s *sqlLoader) addOperatorBundle(tx *sql.Tx, bundle *registry.Bundle) error

addImage, err := tx.Prepare("insert into related_image(image, operatorbundle_name) values(?,?)")
if err != nil {
return err
return fmt.Errorf("failed to insert related image: %s", err)
}
defer addImage.Close()

csvName, bundleImage, csvBytes, bundleBytes, _, err := bundle.Serialize()
if err != nil {
return err
return fmt.Errorf("unable to serialize the bundle : %s", err)
}

if csvName == "" {
Expand All @@ -103,23 +103,23 @@ func (s *sqlLoader) addOperatorBundle(tx *sql.Tx, bundle *registry.Bundle) error

version, err := bundle.Version()
if err != nil {
return err
return fmt.Errorf("unable to obtain bundle version : %s", err)
}
skiprange, err := bundle.SkipRange()
if err != nil {
return err
return fmt.Errorf("unable to obtain skipRange : %s", err)
}
replaces, err := bundle.Replaces()
if err != nil {
return err
return fmt.Errorf("unable to obtain replaces : %s", err)
}
skips, err := bundle.Skips()
if err != nil {
return err
return fmt.Errorf("unable to obtain skips : %s", err)
}
substitutesFor, err := bundle.SubstitutesFor()
if err != nil {
return err
return fmt.Errorf("unable to obtain substitutes : %s", err)
}

if substitutesFor != "" && !s.enableAlpha {
Expand All @@ -132,7 +132,7 @@ func (s *sqlLoader) addOperatorBundle(tx *sql.Tx, bundle *registry.Bundle) error

imgs, err := bundle.Images()
if err != nil {
return err
return fmt.Errorf("unable to obtain images : %s", err)
}
for img := range imgs {
if _, err := addImage.Exec(img, csvName); err != nil {
Expand All @@ -143,18 +143,18 @@ func (s *sqlLoader) addOperatorBundle(tx *sql.Tx, bundle *registry.Bundle) error
// Add dependencies information
err = s.addDependencies(tx, bundle)
if err != nil {
return err
return fmt.Errorf("failed to add dependencies : %s", err)
}

err = s.addBundleProperties(tx, bundle)
if err != nil {
return err
return fmt.Errorf("failed to add properties : %s", err)
}

if s.enableAlpha {
err = s.addSubstitutesFor(tx, bundle)
if err != nil {
return err
return fmt.Errorf("failed to add substitutes : %s", err)
}
}

Expand Down Expand Up @@ -191,19 +191,19 @@ func (s *sqlLoader) addSubstitutesFor(tx *sql.Tx, bundle *registry.Bundle) error

replaces, err := bundle.Replaces()
if err != nil {
return err
return fmt.Errorf("failed to obtain replaces : %s", err)
}
skips, err := bundle.Skips()
if err != nil {
return err
return fmt.Errorf("failed to obtain skips : %s", err)
}
version, err := bundle.Version()
if err != nil {
return err
return fmt.Errorf("failed to obtain version : %s", err)
}
substitutesFor, err := bundle.SubstitutesFor()
if err != nil {
return err
return fmt.Errorf("failed to obtain substitutes : %s", err)
}
if substitutesFor != "" {
// Update any replaces that reference the substituted-for bundle
Expand Down Expand Up @@ -404,7 +404,7 @@ func (s *sqlLoader) appendSkips(tx *sql.Tx, skips []string, csvName string) erro
func (s *sqlLoader) AddPackageChannelsFromGraph(graph *registry.Package) error {
tx, err := s.db.Begin()
if err != nil {
return err
return fmt.Errorf("unable to start a transaction: %s", err)
}
defer func() {
tx.Rollback()
Expand All @@ -424,7 +424,7 @@ func (s *sqlLoader) AddPackageChannelsFromGraph(graph *registry.Package) error {
}

if err := updateDefaultChannel(tx, graph.DefaultChannel, graph.Name); err != nil {
errs = append(errs, err)
errs = append(errs, fmt.Errorf("the default channel (%s) does not exist: %s", graph.DefaultChannel, err))
}

// update each channel's graph
Expand Down Expand Up @@ -507,7 +507,7 @@ func (s *sqlLoader) AddPackageChannelsFromGraph(graph *registry.Package) error {
// If the number of nodes is 5 and the startDepth is 3, the expected depth is 7 (3, 4, 5, 6, 7)
expectedDepth := len(channel.Nodes) + startDepth - 1
if expectedDepth != depth {
err := fmt.Errorf("Invalid graph: some (non-bottom) nodes defined in the graph were not mentioned as replacements of any node")
err := fmt.Errorf("Invalid graph: some (non-bottom) nodes defined in the graph were not mentioned as replacements of any node (%d != %d)", expectedDepth, depth)
errs = append(errs, err)
}
break
Expand All @@ -530,7 +530,7 @@ func (s *sqlLoader) AddPackageChannelsFromGraph(graph *registry.Package) error {
func (s *sqlLoader) AddPackageChannels(manifest registry.PackageManifest) error {
tx, err := s.db.Begin()
if err != nil {
return err
return fmt.Errorf("unable to start a transaction: %s", err)
}
defer func() {
tx.Rollback()
Expand Down Expand Up @@ -1087,7 +1087,7 @@ func (s *sqlLoader) rmPackage(tx *sql.Tx, pkg string) error {
defer deletePkg.Close()
_, err = deletePkg.Exec(pkg)
if err != nil {
return err
return fmt.Errorf("unable to delete the package %s: %s", pkg, err)
}

deleteChan, err := tx.Prepare("DELETE FROM channel WHERE package_name = ?")
Expand All @@ -1098,7 +1098,7 @@ func (s *sqlLoader) rmPackage(tx *sql.Tx, pkg string) error {
defer deleteChan.Close()
_, err = deleteChan.Exec(pkg)
if err != nil {
return err
return fmt.Errorf("unable to delete channel: %s", err)
}

deleteChannelEntries, err := tx.Prepare("DELETE FROM channel_entry WHERE package_name = ?")
Expand Down
20 changes: 11 additions & 9 deletions pkg/sqlite/loadprocs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sqlite

import (
"database/sql"
"fmt"
)

// TODO: Finish separating procedures from loader layer: make this a type to make
Expand All @@ -15,7 +16,7 @@ func addChannelEntry(tx *sql.Tx, channelName, packageName, csvName string, depth

res, err := addChannelEntry.Exec(channelName, packageName, csvName, depth)
if err != nil {
return 0, err
return 0, fmt.Errorf("failed to insert channel_entry for channel (%s) and bundle (%s): %s", channelName, csvName, err)
}
currentID, err := res.LastInsertId()
if err != nil {
Expand All @@ -34,7 +35,7 @@ func addReplaces(tx *sql.Tx, replacesID, entryID int64) error {

_, err = addReplaces.Exec(replacesID, entryID)
if err != nil {
return err
return fmt.Errorf("failed to update channel_entry to set replaces (%d) for entry (%d): %s", replacesID, entryID, err)
}

return nil
Expand All @@ -49,7 +50,7 @@ func addPackage(tx *sql.Tx, packageName string) error {

_, err = addPackage.Exec(packageName)
if err != nil {
return err
return fmt.Errorf("failed to insert package (%s): %s", packageName, err)
}

return nil
Expand All @@ -64,7 +65,7 @@ func addPackageIfNotExists(tx *sql.Tx, packageName string) error {

_, err = addPackage.Exec(packageName)
if err != nil {
return err
return fmt.Errorf("failed to insert or replace package (%s): %s", packageName, err)
}

return nil
Expand All @@ -79,7 +80,7 @@ func addChannel(tx *sql.Tx, channelName, packageName, headCsvName string) error

_, err = addChannel.Exec(channelName, packageName, headCsvName)
if err != nil {
return err
return fmt.Errorf("failed to insert channel (%s) for package (%s) with head (%s) : %s", channelName, packageName, headCsvName, err)
}

return nil
Expand All @@ -94,7 +95,8 @@ func updateChannel(tx *sql.Tx, channelName, packageName, headCsvName string) err

_, err = updateChannel.Exec(channelName, packageName, headCsvName)
if err != nil {
return err
return fmt.Errorf("failed to update channel (%s) for package (%s) with head (%s) : %s", channelName, packageName, headCsvName, err)

}

return nil
Expand All @@ -109,7 +111,7 @@ func addOrUpdateChannel(tx *sql.Tx, channelName, packageName, headCsvName string

_, err = addChannel.Exec(channelName, packageName, headCsvName)
if err != nil {
return err
return fmt.Errorf("failed to insert or update channel (%s) for package (%s) with head (%s) : %s", channelName, packageName, headCsvName, err)
}

return nil
Expand All @@ -124,7 +126,7 @@ func updateDefaultChannel(tx *sql.Tx, channelName, packageName string) error {

_, err = updateDefaultChannel.Exec(channelName, packageName)
if err != nil {
return err
return fmt.Errorf("failed to set default channel (%s) for package (%s): %s", channelName, packageName, err)
}

return nil
Expand All @@ -139,7 +141,7 @@ func truncChannelGraph(tx *sql.Tx, channelName, packageName string) error {

_, err = truncChannelGraph.Exec(channelName, packageName)
if err != nil {
return err
return fmt.Errorf("failed to delete channel entry for channel name (%s) and package (%s): %s", channelName, packageName, err)
}

return nil
Expand Down

0 comments on commit dd41163

Please sign in to comment.