From a7c285bf7ed9e1f5e2aae727ff05d0571c5c07f7 Mon Sep 17 00:00:00 2001 From: Simon Alling Date: Tue, 1 Oct 2019 13:10:26 +0200 Subject: [PATCH] ref(pkg/chartutil): Improve error handling code in Save While working on #6519, it took me hours to figure out why the error returned from `Save` was nil even though `writeTarContents` returned a non-nil error. I fixed the bug as part of that PR; the purpose of this commit is to prevent it from happening again. What made me (as a Go beginner) so confused was the impression that there was only ever one `err` variable, global to the entire `Save` function, when in fact there were also several local ones shadowing it. (I thought := could be used to reassign an existing variable.) This commit makes it clear that any `err` defined locally in the last `if` statement will not be returned at the end, and hence must be explicitly returned in the body of said `if` statement. (This commit initially was larger; see #6669.) Signed-off-by: Simon Alling --- pkg/chartutil/save.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/chartutil/save.go b/pkg/chartutil/save.go index ca6eeaa19..bc8f5bdd9 100644 --- a/pkg/chartutil/save.go +++ b/pkg/chartutil/save.go @@ -135,7 +135,7 @@ func Save(c *chart.Chart, outDir string) (string, error) { rollback = true return filename, err } - return filename, err + return filename, nil } func writeTarContents(out *tar.Writer, c *chart.Chart, prefix string) error {