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 <alling.simon@gmail.com>
pull/6669/head
Simon Alling 5 years ago
parent 3edad39e08
commit a7c285bf7e

@ -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 {

Loading…
Cancel
Save