From 1a7face3a092b06610685cdd69fc0eb9fe275e4a Mon Sep 17 00:00:00 2001 From: Kevin Mulvey Date: Wed, 7 Dec 2022 10:02:27 -0700 Subject: [PATCH] better errors --- internal/app/imagedup/hash/cache.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/app/imagedup/hash/cache.go b/internal/app/imagedup/hash/cache.go index c8f0b1e..65ef8b5 100644 --- a/internal/app/imagedup/hash/cache.go +++ b/internal/app/imagedup/hash/cache.go @@ -2,6 +2,7 @@ package hash import ( "encoding/json" + "errors" "fmt" "image" "image/jpeg" @@ -81,7 +82,11 @@ func NewCache(file, globPattern, promNamespace string, numFiles int) (*Cache, er } for i, hash := range m.Hashes { - c.store[i] = &Image{goimagehash.NewImageHash(hash, goimagehash.PHash), image.Config{}} + if i < len(c.store) { + c.store[i] = &Image{goimagehash.NewImageHash(hash, goimagehash.PHash), image.Config{}} + } else { + return nil, errors.New(fmt.Sprintf("number of hases: %d, does not match store size: %d, delete the cache file: %s", len(m.Hashes), numFiles, file)) + } } }