Skip to content

Commit

Permalink
Make odo build-images return an error if no Image component found
Browse files Browse the repository at this point in the history
As reported in redhat-developer#5330, this makes more sense rather than exiting silently.
  • Loading branch information
rm3l committed Mar 30, 2022
1 parent 6c0b1dd commit de29eb3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/devfile/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
devfile "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
"github.com/devfile/library/pkg/devfile/parser"
"github.com/devfile/library/pkg/devfile/parser/data/v2/common"
"github.com/redhat-developer/odo/pkg/libdevfile"
"github.com/redhat-developer/odo/pkg/log"
)

Expand Down Expand Up @@ -39,6 +40,9 @@ func BuildPushImages(devfileObj parser.DevfileObj, path string, push bool) error
if err != nil {
return err
}
if len(components) == 0 {
return libdevfile.NewComponentTypeNotFoundError(devfile.ImageComponentType)
}

for _, component := range components {
err = buildPushImage(backend, component.Image, path, push)
Expand Down
15 changes: 15 additions & 0 deletions pkg/libdevfile/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,18 @@ func NewNotAContainerError() NotAContainerError {
func (e NotAContainerError) Error() string {
return "component not a container"
}

// ComponentTypeNotFoundError is returned when no component with the specified type has been found in Devfile
type ComponentTypeNotFoundError struct {
componentType v1alpha2.ComponentType
}

func NewComponentTypeNotFoundError(componentType v1alpha2.ComponentType) ComponentTypeNotFoundError {
return ComponentTypeNotFoundError{
componentType: componentType,
}
}

func (e ComponentTypeNotFoundError) Error() string {
return fmt.Sprintf("no component with type %q found in Devfile", e.componentType)
}

0 comments on commit de29eb3

Please sign in to comment.