Return a proper error if phase document was not found

Change-Id: I0b3b7a819b6c76fdc2e20ee2f6f8ece047fac858
Relates-To: #257
Closes: #257
Signed-off-by: Ruslan Aliev <raliev@mirantis.com>
This commit is contained in:
Ruslan Aliev 2020-06-18 03:44:42 -05:00
parent 901c314f02
commit 0314c5c848
3 changed files with 16 additions and 6 deletions

View File

@ -732,11 +732,11 @@ func (c *Config) CurrentContextEntryPoint(phase string) (string, error) {
if !exists { if !exists {
return "", ErrMissingPrimaryRepo{} return "", ErrMissingPrimaryRepo{}
} }
return path.Join( epp := path.Join(ccm.TargetPath, ccm.SubPath, clusterType, phase)
ccm.TargetPath, if _, err := os.Stat(epp); err != nil {
ccm.SubPath, return "", ErrMissingPhaseDocument{PhaseName: phase}
clusterType, }
phase), nil return epp, nil
} }
// CurrentContextTargetPath returns target path from current context's manifest // CurrentContextTargetPath returns target path from current context's manifest

View File

@ -511,7 +511,7 @@ func TestCurrentContextEntryPoint(t *testing.T) {
conf.Contexts[currentContextName].KubeContext().Cluster = clusterName conf.Contexts[currentContextName].KubeContext().Cluster = clusterName
entryPoint, err = conf.CurrentContextEntryPoint(defaultString) entryPoint, err = conf.CurrentContextEntryPoint(defaultString)
require.NoError(t, err) assert.Equal(t, config.ErrMissingPhaseDocument{PhaseName: defaultString}, err)
assert.Nil(t, nil, entryPoint) assert.Nil(t, nil, entryPoint)
} }

View File

@ -179,6 +179,16 @@ func (e ErrMissingPrimaryRepo) Error() string {
return "Current context manifest must have a primary repository set." return "Current context manifest must have a primary repository set."
} }
// ErrMissingPhaseDocument returned when appropriate Phase document was not found in the filesystem
type ErrMissingPhaseDocument struct {
PhaseName string
}
func (e ErrMissingPhaseDocument) Error() string {
return fmt.Sprintf("Phase document '%s' was not found. "+
"You can initialize it using 'airshipctl document init %s' command.", e.PhaseName, e.PhaseName)
}
// ErrConflictingAuthOptions returned in case both token and username/password is set at same time // ErrConflictingAuthOptions returned in case both token and username/password is set at same time
type ErrConflictingAuthOptions struct { type ErrConflictingAuthOptions struct {
} }