From 2c553b17729775448f37f5a2d3b1f7c6aed2b149 Mon Sep 17 00:00:00 2001 From: Julien Date: Tue, 3 Sep 2024 11:37:14 +0200 Subject: [PATCH] autoreload: do not ignore errors Signed-off-by: Julien --- config/reload.go | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/config/reload.go b/config/reload.go index 2f03ca463..8be1b28d8 100644 --- a/config/reload.go +++ b/config/reload.go @@ -36,7 +36,10 @@ func GenerateChecksum(yamlFilePath string) (string, error) { if err != nil { return "", fmt.Errorf("error reading YAML file: %w", err) } - _, _ = hash.Write(yamlContent) + _, err = hash.Write(yamlContent) + if err != nil { + return "", fmt.Errorf("error writing YAML file to hash: %w", err) + } var config ExternalFilesConfig if err := yaml.Unmarshal(yamlContent, &config); err != nil { @@ -61,23 +64,26 @@ func GenerateChecksum(yamlFilePath string) (string, error) { for _, pattern := range files[prefix] { matchingFiles, err := filepath.Glob(pattern) if err != nil { - return "", fmt.Errorf("error finding files with pattern %s: %w", pattern, err) + return "", fmt.Errorf("error finding files with pattern %q: %w", pattern, err) } for _, file := range matchingFiles { - // Write prefix to the hash ("r" or "s") followed by \0. - _, _ = hash.Write([]byte(prefix + "\x00")) - - // Write the file path to the hash, followed by \0 to ensure - // separation. - _, _ = hash.Write([]byte(file + "\x00")) + // Write prefix to the hash ("r" or "s") followed by \0, then + // the file path. + _, err = hash.Write([]byte(prefix + "\x00" + file + "\x00")) + if err != nil { + return "", fmt.Errorf("error writing %q path to hash: %w", file, err) + } // Read and hash the content of the file. content, err := os.ReadFile(file) if err != nil { return "", fmt.Errorf("error reading file %s: %w", file, err) } - _, _ = hash.Write(append(content, []byte("\x00")...)) + _, err = hash.Write(append(content, []byte("\x00")...)) + if err != nil { + return "", fmt.Errorf("error writing %q content to hash: %w", file, err) + } } } }