From b26dd90aea5ddffa9816241f5482c02efca3b29e Mon Sep 17 00:00:00 2001 From: Anshul Verma Date: Tue, 22 Oct 2019 19:06:32 +0530 Subject: [PATCH] Friendly error message for non-existent file/directory Signed-off-by: Anshul Verma Friendly error message for non-existent file/directory Signed-off-by: Anshul Verma Friendly error message for non-existent file/directory Signed-off-by: Anshul Verma --- pkg/chart/metadata.go | 3 ++- pkg/chart/metadata_test.go | 28 ++++++++++++++++++++++++++++ pkg/chartutil/chartfile.go | 2 +- 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 pkg/chart/metadata_test.go diff --git a/pkg/chart/metadata.go b/pkg/chart/metadata.go index 96a3965b9..dfe48c1c7 100644 --- a/pkg/chart/metadata.go +++ b/pkg/chart/metadata.go @@ -67,7 +67,8 @@ type Metadata struct { // Validate checks the metadata for known issues, returning an error if metadata is not correct func (md *Metadata) Validate() error { if md == nil { - return ValidationError("chart.metadata is required") + // if md == nil, it mean 'Chart.yaml' file is not present in the directory. + return ValidationError("Chart.yaml file is missing") } if md.APIVersion == "" { return ValidationError("chart.metadata.apiVersion is required") diff --git a/pkg/chart/metadata_test.go b/pkg/chart/metadata_test.go new file mode 100644 index 000000000..6340357fa --- /dev/null +++ b/pkg/chart/metadata_test.go @@ -0,0 +1,28 @@ +/* +Copyright The Helm Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package chart + +import "testing" + +func TestValidate(t *testing.T) { + var metadata *Metadata = nil + error := metadata.Validate() + errorMessage := "validation: Chart.yaml file is missing" + if error.Error() != errorMessage { + t.Errorf("The error message is other than '%s'", errorMessage) + } +} diff --git a/pkg/chartutil/chartfile.go b/pkg/chartutil/chartfile.go index 68176ed5d..ff7012cc1 100644 --- a/pkg/chartutil/chartfile.go +++ b/pkg/chartutil/chartfile.go @@ -74,7 +74,7 @@ func IsChartDir(dirName string) (bool, error) { return false, err } if chartContent == nil { - return false, errors.Errorf("chart metadata (%s) missing", ChartfileName) + return false, errors.Errorf("(%s) : No such file or directory", ChartfileName) } if chartContent.Name == "" { return false, errors.Errorf("invalid chart (%s): name must not be empty", ChartfileName)