From 0314c5c848082b45ec04734b4f2c1ae3057c3ad9 Mon Sep 17 00:00:00 2001 From: Ruslan Aliev Date: Thu, 18 Jun 2020 03:44:42 -0500 Subject: [PATCH] Return a proper error if phase document was not found Change-Id: I0b3b7a819b6c76fdc2e20ee2f6f8ece047fac858 Relates-To: #257 Closes: #257 Signed-off-by: Ruslan Aliev --- pkg/config/config.go | 10 +++++----- pkg/config/config_test.go | 2 +- pkg/config/errors.go | 10 ++++++++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index ad3936c0e..fcf7d2107 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -732,11 +732,11 @@ func (c *Config) CurrentContextEntryPoint(phase string) (string, error) { if !exists { return "", ErrMissingPrimaryRepo{} } - return path.Join( - ccm.TargetPath, - ccm.SubPath, - clusterType, - phase), nil + epp := path.Join(ccm.TargetPath, ccm.SubPath, clusterType, phase) + if _, err := os.Stat(epp); err != nil { + return "", ErrMissingPhaseDocument{PhaseName: phase} + } + return epp, nil } // CurrentContextTargetPath returns target path from current context's manifest diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index af919bc12..91ac715c0 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -511,7 +511,7 @@ func TestCurrentContextEntryPoint(t *testing.T) { conf.Contexts[currentContextName].KubeContext().Cluster = clusterName entryPoint, err = conf.CurrentContextEntryPoint(defaultString) - require.NoError(t, err) + assert.Equal(t, config.ErrMissingPhaseDocument{PhaseName: defaultString}, err) assert.Nil(t, nil, entryPoint) } diff --git a/pkg/config/errors.go b/pkg/config/errors.go index c516fda88..1a8842f48 100644 --- a/pkg/config/errors.go +++ b/pkg/config/errors.go @@ -179,6 +179,16 @@ func (e ErrMissingPrimaryRepo) Error() string { 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 type ErrConflictingAuthOptions struct { }