From 6a2abc9466e05fd19ebd1052473f7d2f012cee91 Mon Sep 17 00:00:00 2001 From: Chris Hines Date: Wed, 9 Dec 2015 16:34:18 -0500 Subject: [PATCH] Improve error messages. --- client/fingerprint/storage.go | 9 +++++---- client/fingerprint/storage_windows.go | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/client/fingerprint/storage.go b/client/fingerprint/storage.go index 242e0ec30..83adb4515 100644 --- a/client/fingerprint/storage.go +++ b/client/fingerprint/storage.go @@ -10,6 +10,8 @@ import ( "github.com/hashicorp/nomad/nomad/structs" ) +const bytesPerMegabyte = 1024 * 1024 + // StorageFingerprint is used to measure the amount of storage free for // applications that the Nomad agent will run on this machine. type StorageFingerprint struct { @@ -38,21 +40,20 @@ func (f *StorageFingerprint) Fingerprint(cfg *config.Config, node *structs.Node) var err error storageDir, err = os.Getwd() if err != nil { - return false, fmt.Errorf("Unable to get CWD from filesystem: %s", err) + return false, fmt.Errorf("unable to get CWD from filesystem: %s", err) } } volume, total, free, err := f.diskFree(storageDir) if err != nil { - return false, err + return false, fmt.Errorf("failed to determine disk space for %s: %v", storageDir, err) } node.Attributes["storage.volume"] = volume node.Attributes["storage.bytestotal"] = strconv.FormatUint(total, 10) node.Attributes["storage.bytesfree"] = strconv.FormatUint(free, 10) - const mb = 1024 * 1024 - node.Resources.DiskMB = int(free / mb) + node.Resources.DiskMB = int(free / bytesPerMegabyte) return true, nil } diff --git a/client/fingerprint/storage_windows.go b/client/fingerprint/storage_windows.go index 68ad1b6fd..716f1baf0 100644 --- a/client/fingerprint/storage_windows.go +++ b/client/fingerprint/storage_windows.go @@ -22,11 +22,11 @@ func (f *StorageFingerprint) diskFree(path string) (volume string, total, free u absPathp, err := syscall.UTF16PtrFromString(absPath) if err != nil { - return "", 0, 0, fmt.Errorf("failed to determine disk space for %s: %v", absPath, err) + return "", 0, 0, fmt.Errorf("failed to convert \"%s\" to UTF16: %v", absPath, err) } if err := getDiskFreeSpaceEx(absPathp, nil, &total, &free); err != nil { - return "", 0, 0, fmt.Errorf("failed to determine disk space for %s: %v", absPath, err) + return "", 0, 0, fmt.Errorf("failed to get free disk space for %s: %v", absPath, err) } return volume, total, free, nil