From 096d70507603ec05c2ea43126838778e35dc1999 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Wed, 17 Mar 2021 23:17:01 +0200 Subject: [PATCH] cleanup after 5a49bb8e88e070e43cbffaa68776259f11f6c053 --- process_metrics_linux.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/process_metrics_linux.go b/process_metrics_linux.go index 0e0386c..12b5de8 100644 --- a/process_metrics_linux.go +++ b/process_metrics_linux.go @@ -236,17 +236,18 @@ func getMemStats(path string) (*memStats, error) { // Extract key value. line := strings.Fields(s) if len(line) != 3 { - return nil, fmt.Errorf("cannot extract soft limit from %q", s) + return nil, fmt.Errorf("unexpected number of fields found in %q; got %d; want %d", s, len(line), 3) } memStatName := line[0] memStatValue := line[1] value, err := strconv.ParseUint(memStatValue, 10, 64) if err != nil { - return nil, fmt.Errorf("cannot parse soft limit from %q: %s", s, err) + return nil, fmt.Errorf("cannot parse number from %q: %w", s, err) } - if line[2] == "kB" { - value = value * 1024 + if line[2] != "kB" { + return nil, fmt.Errorf("expecting kB value in %q; got %q", s, line[2]) } + value *= 1024 switch memStatName { case "VmPeak:": ms.vmPeak = value