...

Source file src/github.com/redhat-developer/odo/pkg/libdevfile/errors.go

Documentation: github.com/redhat-developer/odo/pkg/libdevfile

     1  package libdevfile
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
     7  )
     8  
     9  // NoCommandFoundError is returned when no command of the specified kind is found in devfile
    10  type NoCommandFoundError struct {
    11  	kind v1alpha2.CommandGroupKind
    12  	name string
    13  }
    14  
    15  func NewNoCommandFoundError(kind v1alpha2.CommandGroupKind, name string) NoCommandFoundError {
    16  	return NoCommandFoundError{
    17  		kind: kind,
    18  		name: name,
    19  	}
    20  }
    21  func (e NoCommandFoundError) Error() string {
    22  	if e.name == "" {
    23  		return fmt.Sprintf("no %s command found in devfile", e.kind)
    24  	}
    25  	if e.kind == "" {
    26  		return fmt.Sprintf("no command named %q found in devfile", e.name)
    27  	}
    28  	return fmt.Sprintf("no %s command with name %q found in Devfile", e.kind, e.name)
    29  }
    30  
    31  // NoDefaultCommandFoundError is returned when several commands of the specified kind exist
    32  // but no one is the default one
    33  type NoDefaultCommandFoundError struct {
    34  	kind v1alpha2.CommandGroupKind
    35  }
    36  
    37  func NewNoDefaultCommandFoundError(kind v1alpha2.CommandGroupKind) NoDefaultCommandFoundError {
    38  	return NoDefaultCommandFoundError{
    39  		kind: kind,
    40  	}
    41  }
    42  func (e NoDefaultCommandFoundError) Error() string {
    43  	return fmt.Sprintf("no default %s command found in devfile", e.kind)
    44  }
    45  
    46  // MoreThanOneDefaultCommandFoundError is returned when several default commands of the specified kind exist
    47  type MoreThanOneDefaultCommandFoundError struct {
    48  	kind v1alpha2.CommandGroupKind
    49  }
    50  
    51  func NewMoreThanOneDefaultCommandFoundError(kind v1alpha2.CommandGroupKind) MoreThanOneDefaultCommandFoundError {
    52  	return MoreThanOneDefaultCommandFoundError{
    53  		kind: kind,
    54  	}
    55  }
    56  func (e MoreThanOneDefaultCommandFoundError) Error() string {
    57  	return fmt.Sprintf("more than one default %s command found in devfile, this should not happen", e.kind)
    58  }
    59  
    60  // ComponentNotExistError is returned when a component referenced in a command or component does not exist
    61  type ComponentNotExistError struct {
    62  	name string
    63  }
    64  
    65  func NewComponentNotExistError(name string) ComponentNotExistError {
    66  	return ComponentNotExistError{
    67  		name: name,
    68  	}
    69  }
    70  
    71  func (e ComponentNotExistError) Error() string {
    72  	return fmt.Sprintf("component %q does not exists", e.name)
    73  }
    74  
    75  type ComponentsWithSameNameError struct {
    76  	name string
    77  }
    78  
    79  func NewComponentsWithSameNameError(name string) ComponentsWithSameNameError {
    80  	return ComponentsWithSameNameError{
    81  		name: name,
    82  	}
    83  }
    84  
    85  func (e ComponentsWithSameNameError) Error() string {
    86  	return fmt.Sprintf("more than one component with the same name %q, should not happen", e.name)
    87  }
    88  
    89  // ComponentTypeNotFoundError is returned when no component with the specified type has been found in Devfile
    90  type ComponentTypeNotFoundError struct {
    91  	componentType v1alpha2.ComponentType
    92  }
    93  
    94  func NewComponentTypeNotFoundError(componentType v1alpha2.ComponentType) ComponentTypeNotFoundError {
    95  	return ComponentTypeNotFoundError{
    96  		componentType: componentType,
    97  	}
    98  }
    99  
   100  func (e ComponentTypeNotFoundError) Error() string {
   101  	return fmt.Sprintf("no component with type %q found in Devfile", e.componentType)
   102  }
   103  
   104  // NoCommandForGroup indicates an error when no command was found for the given Group
   105  type NoCommandForGroup struct {
   106  	Group v1alpha2.CommandGroupKind
   107  }
   108  
   109  func (n NoCommandForGroup) Error() string {
   110  	return fmt.Sprintf("the command group of kind \"%v\" is not found in the devfile", n.Group)
   111  }
   112  

View as plain text