mirror of
https://github.com/helm/helm.git
synced 2026-04-15 21:59:50 -04:00
Use errors.Is to check for io.EOF and gzip.ErrHeader
In GoLang, using the == operator to check for a certain error will not unwrap the error chain, and therefore may hide the problem. Signed-off-by: Mads Jensen <atombrella@users.noreply.github.com>
This commit is contained in:
parent
5d2ab10caa
commit
a490bb3c20
19 changed files with 29 additions and 23 deletions
|
|
@ -70,7 +70,7 @@ func Crds(linter *support.Linter) {
|
|||
var yamlStruct *k8sYamlStruct
|
||||
|
||||
err := decoder.Decode(&yamlStruct)
|
||||
if err == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
break
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ func TemplatesWithSkipSchemaValidation(linter *support.Linter, values map[string
|
|||
var yamlStruct *k8sYamlStruct
|
||||
|
||||
err := decoder.Decode(&yamlStruct)
|
||||
if err == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
break
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ func LoadFile(name string) (*chart.Chart, error) {
|
|||
|
||||
c, err := LoadArchive(raw)
|
||||
if err != nil {
|
||||
if err == gzip.ErrHeader {
|
||||
if errors.Is(err, gzip.ErrHeader) {
|
||||
return nil, fmt.Errorf("file '%s' does not appear to be a valid chart file (details: %s)", name, err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -189,7 +189,7 @@ func LoadValues(data io.Reader) (map[string]interface{}, error) {
|
|||
currentMap := map[string]interface{}{}
|
||||
raw, err := reader.Read()
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
break
|
||||
}
|
||||
return nil, fmt.Errorf("error reading yaml document: %w", err)
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import (
|
|||
"archive/tar"
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"errors"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
|
|
@ -116,7 +117,7 @@ func TestBomTestData(t *testing.T) {
|
|||
tr := tar.NewReader(unzipped)
|
||||
for {
|
||||
file, err := tr.Next()
|
||||
if err == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import (
|
|||
"bytes"
|
||||
"compress/gzip"
|
||||
"crypto/sha256"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
|
@ -201,7 +202,7 @@ func retrieveAllHeadersFromTar(path string) ([]*tar.Header, error) {
|
|||
headers := []*tar.Header{}
|
||||
for {
|
||||
hd, err := tr.Next()
|
||||
if err == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
break
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ func (g *TarGzExtractor) Extract(buffer *bytes.Buffer, targetDir string) error {
|
|||
tarReader := tar.NewReader(uncompressedStream)
|
||||
for {
|
||||
header, err := tarReader.Next()
|
||||
if err == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import (
|
|||
"archive/tar"
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log/slog"
|
||||
|
|
@ -214,7 +215,7 @@ func extractTar(r io.Reader, targetDir string) error {
|
|||
|
||||
for {
|
||||
header, err := tarReader.Next()
|
||||
if err == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ func ExtractTgzPluginMetadata(r io.Reader) (*Metadata, error) {
|
|||
tr := tar.NewReader(gzr)
|
||||
for {
|
||||
header, err := tr.Next()
|
||||
if err == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ func LoadArchiveFiles(in io.Reader) ([]*BufferedFile, error) {
|
|||
for {
|
||||
b := bytes.NewBuffer(nil)
|
||||
hd, err := tr.Next()
|
||||
if err == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -131,8 +131,8 @@ func LoadFile(name string) (chart.Charter, error) {
|
|||
|
||||
files, err := archive.LoadArchiveFiles(raw)
|
||||
if err != nil {
|
||||
if err == gzip.ErrHeader {
|
||||
return nil, fmt.Errorf("file '%s' does not appear to be a valid chart file (details: %s)", name, err)
|
||||
if errors.Is(err, gzip.ErrHeader) {
|
||||
return nil, fmt.Errorf("file '%s' does not appear to be a valid chart file (details: %w)", name, err)
|
||||
}
|
||||
return nil, errors.New("unable to load chart archive")
|
||||
}
|
||||
|
|
@ -163,7 +163,7 @@ func LoadArchive(in io.Reader) (chart.Charter, error) {
|
|||
|
||||
files, err := archive.LoadArchiveFiles(in)
|
||||
if err != nil {
|
||||
if err == gzip.ErrHeader {
|
||||
if errors.Is(err, gzip.ErrHeader) {
|
||||
return nil, fmt.Errorf("stream does not appear to be a valid chart file (details: %w)", err)
|
||||
}
|
||||
return nil, fmt.Errorf("unable to load chart archive: %w", err)
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ func Crds(linter *support.Linter) {
|
|||
var yamlStruct *k8sYamlStruct
|
||||
|
||||
err := decoder.Decode(&yamlStruct)
|
||||
if err == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
break
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -180,7 +180,7 @@ func (t *templateLinter) Lint() {
|
|||
var yamlStruct *k8sYamlStruct
|
||||
|
||||
err := decoder.Decode(&yamlStruct)
|
||||
if err == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
break
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,8 +56,8 @@ func LoadFile(name string) (*chart.Chart, error) {
|
|||
|
||||
c, err := LoadArchive(raw)
|
||||
if err != nil {
|
||||
if err == gzip.ErrHeader {
|
||||
return nil, fmt.Errorf("file '%s' does not appear to be a valid chart file (details: %s)", name, err)
|
||||
if errors.Is(err, gzip.ErrHeader) {
|
||||
return nil, fmt.Errorf("file '%s' does not appear to be a valid chart file (details: %w)", name, err)
|
||||
}
|
||||
}
|
||||
return c, err
|
||||
|
|
|
|||
|
|
@ -216,7 +216,7 @@ func LoadValues(data io.Reader) (map[string]interface{}, error) {
|
|||
currentMap := map[string]interface{}{}
|
||||
raw, err := reader.Read()
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
break
|
||||
}
|
||||
return nil, fmt.Errorf("error reading yaml document: %w", err)
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import (
|
|||
"archive/tar"
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"errors"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
|
|
@ -116,7 +117,7 @@ func TestBomTestData(t *testing.T) {
|
|||
tr := tar.NewReader(unzipped)
|
||||
for {
|
||||
file, err := tr.Next()
|
||||
if err == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import (
|
|||
"bytes"
|
||||
"compress/gzip"
|
||||
"crypto/sha256"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
|
@ -205,7 +206,7 @@ func retrieveAllHeadersFromTar(path string) ([]*tar.Header, error) {
|
|||
headers := []*tar.Header{}
|
||||
for {
|
||||
hd, err := tr.Next()
|
||||
if err == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
break
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ package strvals
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
|
|
@ -66,7 +67,7 @@ func (t *literalParser) parse() error {
|
|||
if err == nil {
|
||||
continue
|
||||
}
|
||||
if err == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
|
|
@ -183,7 +184,7 @@ func (t *literalParser) listItem(list []interface{}, i, nestedNameLevel int) ([]
|
|||
|
||||
case lastRune == '=':
|
||||
value, err := t.val()
|
||||
if err != nil && err != io.EOF {
|
||||
if err != nil && !errors.Is(err, io.EOF) {
|
||||
return list, err
|
||||
}
|
||||
return setIndex(list, i, string(value))
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ func (t *parser) parse() error {
|
|||
if err == nil {
|
||||
continue
|
||||
}
|
||||
if err == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
|
|
|
|||
Loading…
Reference in a new issue